Solved

specifying value for checkbox when unchecked

Posted on 2003-11-19
5
677 Views
Last Modified: 2010-04-09
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.
0
Comment
Question by:stallon123
  • 2
  • 2
5 Comments
 
LVL 11

Assisted Solution

by:Zontar
Zontar earned 125 total points
ID: 9777490
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
 
LVL 33

Accepted Solution

by:
knightEknight earned 125 total points
ID: 9779440
or, similarly in JSP:

String replacement = request.getParameter("replacement");
if ( replacement == null )
   replacement = "No";
0
 
LVL 11

Expert Comment

by:Zontar
ID: 9779550
Thanks, I've never worked with JSPs, just PHP, ASP, and a bit of Python and CF here and there.
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 9781389
and I've done nothing but JSP and ASP :)
0
 

Author Comment

by:stallon123
ID: 9784970
thanks
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

838 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question