Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

specifying value for checkbox when unchecked

Posted on 2003-11-19
5
Medium Priority
?
681 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 11

Assisted Solution

by:Zontar
Zontar earned 375 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 375 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

670 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