Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

determine radio status using JSP

Status
Not open for further replies.

kncd2005

Programmer
May 31, 2005
14
US
Hi,

I am trying to find a way to get the status (i.e. selected or unselected) of a radio group. Whatever radio button is selected, I want to get its value and store that value in a String variable. How can this be done? Thanks in advance for your help.

CD
 
request the radio button, if u get a value then it will be the selected radio button's value...

Known is handfull, Unknown is worldfull
 
I, as well, am having issues with some radio buttons. Here is my code:

-- first JSP --

<html>
<body bgcolor="#CCCC99">
<table>
<form method=get action=display.jsp>
<tr>
<td>Name: <input type="text" name="usrname" size="15"></td>
</tr>
<tr>
<td><input type="submit" value="Go!"></td>
</tr>
<tr>
<td><input type="radio" value="Yes" name="button">Yes</td>
<td><input type="radio" value="No" name="button">No</td>
</tr>
</form>
</table>
</body>
</html>

-- second JSP --

<%@ page import="javax.servlet.*" %>
<html>
<% if(request.getParameter("button") == "Yes"){ %>
Hello, <%= request.getParameter("usrname") %>.
<% } else { %>
Sorry, you don't want your name displayed.
<% }; %>
</html>

The problem is that the "if" statement is always returning false. I changed the "==" to "!=" and the initial condition ran. I do not see how this could be possible. Moreover, is there an implicit conversion between a "response" object and a string object for the string comparison operator or do I need to do that manually (using casting)?

Thanks in advance.
 
>>request.getParameter

is that how u read Get variables???

Known is handfull, Unknown is worldfull
 
Hi danglingpointers,

The if always returns false because you didn't compare String correctly. Try this.

if(request.getParameter("button").equalsIgnoreCase("Yes"))

Hope it helps.
 
That's because == just compares the object, not the values.

Try equals instead.

Cheers,

Dian
 
Ah, that's right. It has been too long since I have done much Java programming. C++ all the way!

Thanks for your help, everyone. I shall certainly be coming back here for any further inquiries.

- Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top