specifying value for checkbox when unchecked

I have a checkbox as follows

<INPUT TYPE="checkbox" NAME="replacement" value="yes" <%if(replacement.equalsIgnoreCase("yes")) { %>checked<% } %> onclick="SetState(this, this.form.details)" >

The "replacement" value is derived from database. If the replacement is "yes" then checkbox is displayed as checked otherwise unchecked. the problem is whenever the checkbox is unchecked null goes as its value. I want "yes" to go into the database(on submitting the form) when it is checked and "no" when it is unchecked.
plz help.
stallon123Asked:
Who is Participating?
 
knightEknightCommented:
or, similarly in JSP:

String replacement = request.getParameter("replacement");
if ( replacement == null )
   replacement = "No";
0
 
ZontarCommented:
Unchecked checkboxes don't get submitted with forms. If you need an "off" value, either use a pair of radiobuttons (with one of them checked by default so the user can't submit the form without one of the two being checked) or test specifically for the null value:

<%
  If IsNull(Request.Form("replacement")) Then
    Replacement = "no"
  Else
    Replacement = Request.Form("replacement")
  End If
%>

or whatever the equivalent is in the language you're using (JSP I suspect?).
0
 
ZontarCommented:
Thanks, I've never worked with JSPs, just PHP, ASP, and a bit of Python and CF here and there.
0
 
knightEknightCommented:
and I've done nothing but JSP and ASP :)
0
 
stallon123Author Commented:
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.