Servlet retrieve pre selected radio button

etlds

I pre select my radio buttons by the following code. The following inputs wrap in a form that post back to the same servlet.

buf.append("<input type=\"radio\" name=\"FTNAME\" value=\""+ FTNAME+ "\" " + (FTNAME.equals("Arial") ? "checked=\"checked\"" : "") + ">Arial &nbsp &nbsp &nbsp");
buf.append("<input type=\"radio\" name=\"FTNAME\" value=\""+ FTNAME+ "\" " + (FTNAME.equals("Serif") ? "checked=\"checked\"" : "") + ">Serif &nbsp &nbsp &nbsp");
buf.append("<input type=\"radio\" name=\"FTNAME\" value=\""+ FTNAME+ "\" " + (FTNAME.equals("SansSerif") ? "checked=\"checked\"" : "") + ">SansSerif <br><br>");

However, when I try to do

FTNAME = request.getParameter("FTNAME") == null ? "Arial" : request.getParameter("FTNAME"); //Arial as font name default

to get my FTNAME, it always return what it was set from the code above, not my new selection.

Any suggestion?

Sas

Because you're setting your value as Arial for all three radio buttons. So no matter what radio button you choose it will always return you arial.

This how your html page would look like:

<input type="radio" name="FTNAME" value="Arial" checked="checked">
<input type="radio" name="FTNAME" value="Arial">
<input type="radio" name="FTNAME" value="Arial">

And you servlet request.getParameter("FTNAME") would alway return you the value "Arial". You need to change to something like this

buf.println("<input type=\"radio\" name=\"FTNAME\" value=\"Arial\"" + (FTNAME.equals("Arial") ? "checked=\"checked\"" : "") + ">Arial &nbsp &nbsp &nbsp");
buf.println("<input type=\"radio\" name=\"FTNAME\" value=\"Serif\""+ (FTNAME.equals("Serif") ? "checked=\"checked\"" : "") + ">Serif &nbsp &nbsp &nbsp");
buf.println("<input type=\"radio\" name=\"FTNAME\" value=\"SansSerif\""+ (FTNAME.equals("SansSerif") ? "checked=\"checked\"" : "") + ">SansSerif <br><br>");

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related