Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

get value from radio button

 
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.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<code>
Try using request.getParameter('radiobuttonname')
</code>
 
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is it single radio button or radio button group?
 
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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("jdbc:odbc: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
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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 .
 
Marshal
Posts: 25838
69
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.
 
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!
 
There is no beard big enough to make me comfortable enough with my masculinity to wear pink. Tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic