wood burning stoves 2.0*
The moose likes JSP and the fly likes get value from radio button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "get value from radio button" Watch "get value from radio button" New topic
Author

get value from radio button

pradeepa sakthi
Greenhorn

Joined: Dec 26, 2008
Posts: 11
can someone help me?how can i get value from radio button to store database in jsp code.
peddi sk
Greenhorn

Joined: Dec 07, 2008
Posts: 5
<code>
Try using request.getParameter('radiobuttonname')
</code>
Sandeep Bhandari
Ranch Hand

Joined: Apr 16, 2004
Posts: 201
is it single radio button or radio button group?


SCJP 96% | SCWCD 90%| SCJP mock exams | My SCJP blog
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

"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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
pradeepa sakthi
Greenhorn

Joined: Dec 26, 2008
Posts: 11
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

Joined: Jan 10, 2002
Posts: 61103
    
  66

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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Dec 17, 2008
Posts: 32
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!


Venki
http://saalram.com
 
jQuery in Action, 2nd edition
 
subject: get value from radio button