Forums Register Login

Retrieving values using option buttons.. please help!!

+Pie Number of slices to send: Send
Hi,
I am retrieving values from a database to a JSP page and I have option buttons for some of these values. But each time the page retrieves stuff, the option buttons are not showing the values, but showing the default options checked! The functions I'm using are isGenderSelected() and isAuthorizationSelected(). Could someone please point out what I'm doing wrong?
The following is the relevant code. Sorry, it's a bit lengthy!
Thank y'all!!!

<HTML>
<BODY BGCOLOR=#FFFFFF>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.lang.*" %>
<%@ page import="java.io.*" %>
<%@ page session="true"%>
<%String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc:odbc:Resume";
String userId = (String)session.getAttribute("Ssn");
Class.forName(driver);
Connection con=null;

try{

con=DriverManager.getConnection(url);

Statement stmt=con.createStatement();
String query="SELECT * FROM Profile WHERE Ssn="+userId;
ResultSet rs=stmt.executeQuery(query);
while(rs.next()){
int ssn=rs.getInt(1);
String lastName=rs.getString(2);
String firstName=rs.getString(3);
String gender=rs.getString(4);
String authorization=rs.getString(5);
public String isGenderSelected(String s) {
return (gender.equals(s))? "checked" : "";
}
public String isAuthorizationSelected(String s) {
return (authorization.equals(s))? "checked" : "";
}
%>
<table>
<tr><td>
<input maxLength="9" name="ssn" size="9" value='<%=userId%>'> </td></tr>
<tr><td>
<input name="lastName" size="20" value='<%=lastName%>'> </td></tr>
<tr><td>
<input name="firstName" size="20" value='<%=firstName%>'>
</td></tr>
<tr><td>
<input CHECKED name="gender" type="radio" value="MALE" <%=s.isGenderSelected("MALE")%>>
</td></tr>
<tr><td>
<input name="gender" type="radio" value="FEMALE" <%=s.isGenderSelected("FEMALE")%>>
</td></tr>
<tr><td>
<input CHECKED name="authorization" type="radio" value="YES" <%=s.isAuthorizationSelected("YES")%>>
<input name="authorization" type="radio" value="NO" <%=s.isAuthorizationSelected("NO")%>>
</td></tr>
</table>
<%
}
rs.close();
rs=null;
stmt.close();
stmt=null;
}
finally{
if(con!=null){
con.close();}
}
%>
</BODY>
</HTML>

+Pie Number of slices to send: Send
Just guessing at this point, but maybe "equalsIgnoreCase"???
+Pie Number of slices to send: Send
Brian, thank you for the reply! But the same methods are working in another jsp page. The only difference is that, in that case, I'm calling the same methods from a class file, any ideas??
Thank you once again!!
+Pie Number of slices to send: Send
you have to conditionally include the text "CHECKED" based on the value returned by the method.You appear to write it regardless.
Dave.
+Pie Number of slices to send: Send
I think the same. you have to check conditionally.
Instead of declaring two methods , check these directyl
Binu
If you have a bad day in October, have a slice of banana cream pie. And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1367 times.
Similar Threads
Problem integrating Input box with JSP
servlet & JDBC connection
multiple javascript functions are not working properly
How to Validate duplicate entries in database using struts1
calling a java Script file into the Jsp
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 02:48:45.