View Full Version : Form 'checkbox' to return a value if it is not ticked?

10-17-2003, 08:36 PM
I need a few check boxes to return a value if they are not checked.


if the tick the 'box1' the form returns the value ...
if you don't tick 'box1' the form returns the value ...

Here's the HTML page so far ...

<script language="JavaScript" type="text/JavaScript">
function DoCheck() {
if(document.form.box1.checked == false)
(document.form.box1.value = "NO");
if(document.form.box2.checked == false)
(document.form.box2.value = "NO");

<title>Form Test</title>

<form action="mailer.asp" method="post" name="form">
<input name="_recipients" type="hidden" value="animations@ntlworld.com">
<input name="_replyToField" type="hidden" value="Email">
<input name="_subject" type="hidden" value="Form Test">
<input name="_redirect" type="hidden" value="test.htm">
<input type="checkbox" name="box1" value="YES">
<input type="checkbox" name="box2" value="YES">
<input type="submit" onClick="DoCheck()">

10-17-2003, 08:56 PM
Sorry, not gonna happen. That's just the way HTML Forms work. You should validate all incoming fields in your server-side script anyway; if you absolutely require a value be passed, use radio buttons and preselect one.

10-17-2003, 09:09 PM
Would it be possible to dynamically create a hidden field if a checkbox has not been ticked? ... (i.e. have a hidden field that is updated by the status of a checkbox). At the moment NOTHING is sent to the form unless a checkbox is ticked. For auditing reasons I need a 'NO' sent to the mail-script if the box isn't ticked ...

Oh, the client is adament that they are checkboxes.
... I guess they don't want their clients to actually have the direct option to select 'NO'

10-17-2003, 11:37 PM
well one way is to have a checkbox under a different name,
and have a hidden text field with the original name

and prior to submitting the form, check if the checkbox
has been checked, and set hidden value to YES,
if not set to NO, then reset the checkbox to false,
so it doesn't get returned,


Ex. If checkbox name is "WANTSPAM" make it say

and have a HIDDEN TEXT field NAME="WANTSPAM"

Have an OnSubmit="" event in the form, which
will check WANTSPAM-CK.checked for true and
assign "YES" to WANTSPAM, otherwise assign "NO"
to WANTSPAM, then set WANTSPAM-CK.checked to


10-18-2003, 04:47 PM
when a checkbox is not checked, it will not be submitted to the server. That is really the behavior of checboxes, radios, single selects.

If you request.form a checkbox and it has no value, it means that it is not checked.

chk = request.form("checkboxname")
if chk <>"" then
'not checked, do something
end if