Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-17-2003, 07:36 PM   PM User | #1
EvvO2004
New to the CF scene

 
Join Date: Oct 2003
Location: UK
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
EvvO2004 is an unknown quantity at this point
Form 'checkbox' to return a value if it is not ticked?

I need a few check boxes to return a value if they are not checked.

e.g...

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

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");
}
</script>

<title>Form Test</title>
</head>

<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()">
</form>
EvvO2004 is offline   Reply With Quote
Old 10-17-2003, 07:56 PM   PM User | #2
Choopernickel
Regular Coder

 
Join Date: Apr 2003
Location: Atlanta, GA
Posts: 487
Thanks: 0
Thanked 0 Times in 0 Posts
Choopernickel is an unknown quantity at this point
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.
Choopernickel is offline   Reply With Quote
Old 10-17-2003, 08:09 PM   PM User | #3
EvvO2004
New to the CF scene

 
Join Date: Oct 2003
Location: UK
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
EvvO2004 is an unknown quantity at this point
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'
EvvO2004 is offline   Reply With Quote
Old 10-17-2003, 10:37 PM   PM User | #4
ggallen
Regular Coder

 
Join Date: Jul 2003
Location: NJ - #29 if you must know
Posts: 117
Thanks: 0
Thanked 0 Times in 0 Posts
ggallen is an unknown quantity at this point
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,

George

Ex. If checkbox name is "WANTSPAM" make it say
WANTSPAM-CK,

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
false.

George
ggallen is offline   Reply With Quote
Old 10-18-2003, 03:47 PM   PM User | #5
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
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
'checked
else
'not checked, do something
end if
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:00 PM.


Advertisement
Log in to turn off these ads.