• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

get value from radio button

 
pradeepa sakthi
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can someone help me?how can i get value from radio button to store database in jsp code.
 
peddi sk
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<code>
Try using request.getParameter('radiobuttonname')
</code>
 
Sandeep Bhandari
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is it single radio button or radio button group?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65118
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"devi", you have previously been warned on multiple occasions regarding adjusting your display name to meet JavaRanch standards. This is not optional, and this is your final warning. Adjust your display name to comply with the required standards prior to your next post.

Your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Failure to comply will result in the removal of your account.

bear
JavaRanch Sheriff
 
pradeepa sakthi
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you sandeep and devi for response,

My HTML code :
<form action="reg.jsp">

<input name="R1" type="radio" value="radiobutton" checked>
Male
<input name="R2" type="radio" value="radiobutton">
Female

<input type="submit" name="Submit" value="Submit">

</form>

Jsp Code:

<%@ page import="java.sql.*"%>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbcdbc:hdsn");if((R1==Checked)&& equals("Male"))
{
String Sex=request.getParameter("R1");
else
{
String Sex=request.getParameter("R2");
PreparedStatement ps=con.prepareStatement("insert into computer values(?)");
ps.setString(1,Sex);
ps.executeUpdate();
%>
<%
}
}
%>
when i compile my code..it should displayed
Syntax: "}" inserted to complete StatementNoShortIf

ERROR..

i don't know..whether it is Misplaced Parenthesis in my code..
please help me.how can i store Radio button value into database..
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65118
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the .
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I suggest that you first put that Java code into a plain old Java class, and not in a JSP? The error message suggests that your brackets aren't matched. Since you posted without indentation it's hard to tell which brackets are right and which are wrong.

And also, it's even harder to tell that in a scriptlet with all those <% things cluttering up the code. I can see at least two obvious errors in your code which will cause problems, and there are a couple of un-obvious errors.

So as I said, get the code to compile in an ordinary Java class first. Get it to run there as well, if you can. Only then should you put it into your JSP. And you should only put it into a JSP if you are being forced to use obsolete practices like scriptlets in JSP.
 
Venki Ananth
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi pradeepa! why did you use two different radio button names? User can select both if you did like this.

code:
--------------------------------------------------------------------------------

if((R1==Checked)&& equals("Male"))

--------------------------------------------------------------------------------

How will you check this condition before getting radio button value? check if else brace! Insane code!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic