Solved

specifying value for checkbox when unchecked

Posted on 2003-11-19
5
668 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now