Solved

specifying value for checkbox when unchecked

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

911 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

20 Experts available now in Live!

Get 1:1 Help Now