All My Checkboxes are passed as "on", whether or n
All my checkboxes are passed as "on", whether or not
they are checked.
I have a multi-page form.
One of those pages has 8 checkboxes on it -- each with a different name.
I am not yet up to passing these values to a server -- instead I send the values (via a cookie) to a final "thank you" page, where I display the fields that the user typed in on each page.
My problem is this -- if none of those checkboxes are checked, the value property of each checkbox is seen in the debugger (and via alert boxes) to be set to "on" (even though it was not checked) and the checked property of each checkbox is set to 0 [is 0 = "false" and -1 = "true" in JavaScript?].
I got around this my putting in a series of if statements for each field (very klugy, especially for 8 different fields -- but it worked)
e.g.,
var myForm = document.frmPage3;
if (myForm.skill_com.checked == true)
myForm.skill_com.value = "yes"
else
myForm.skill_com.value = "no";
if (myForm.skill_db.checked == true)
myForm.skill_db.value = "yes"
else
myForm.skill_db.value = "no";
etc.
I tried using the example below from page 208 of the Wrox Beginning JavaScript book, but it did not work
(in the debugger, when element.type equalled "checkbox" & element.checked was not equal to true, element.value remained as "on", & not "no" -- conversely, when element.checked was equal to true, element.value remained as "on", & not "yes")
var element;
for (var i = 0; i < myForm.length; i++){
element = myForm[i];
if (element.type == "checkbox"){
if (element.checked == true){
element.value == "yes";
} // end inner-if
else {
element.value == "no";
} // end inner-else
} // end outer if
} // end for-loop
There's got to be a better way to do this!
Can someone please help?
Thanks in advance.
|