jmoponfire
Programmer
If I have a form, with one checkbox, why does the length attribute return a value of undefined? Also, why can't I access the zero'th element in a single checkbox as in:
if(which.Question_1[0].checked)?
To see how this is causing a problem for me:
or
if(which.Question_1[0].checked)?
To see how this is causing a problem for me:
or
Code:
<html>
<head>
<script>
function checkQuestion_1(which){
myOption = -1;
for (i=0; i<which.Question_1.length; i++) {
if (which.Question_1[i].checked) {
myOption = i;
}
}
if (myOption == -1) {
alert("You must agree to the terms before continuing");
return false;
}
else
return true;
};
</script>
</head>
<form onsubmit='return (checkQuestion_1(this))'>
<body>
I Agree to the terms:
<input type=checkbox name='Question_1' value='1'>
<input type=submit name=submit value='Continue'>
[\code]
If I have two or more checkboxes this function works fine.
I understand there may be an entirely different approach to do this, but I am working with an application that dynamically generates the j.s. so I'd like to find the most simple fix possible, as this simple smidge of code comes from something more involved. I've just traced it to this simple problem.
Thanks for any help.