I have a basic question and will appreciate your help. I searched quickly in the forum but couldn't find an answer.
Let's suppose I would like visitors to subscribe to either or both of two proposed newsletters. Let's call them "list 98" and "list 99". Obviously, visitors should check at least one checkbox.
I'm no javascipt geek, and I've been working on this snippet of code for over 24 hours now. Yeah! I can hear you laughing
.
The thing is that my script works if the visitor checks one or two checkboxes, but if both are left unchecked, I get a bunch of warnings from signup.php! I must be missing something obvious here, I have no background in JS, just trial and error, and alot of fun!
So here's my JS code:
<script language="Javascript">
<!-- Function that checks that at least one box is checked
function notChecked( box )
{
if( box.checked )
{
return false;
}
else
{
return true;
}
}
// Checking the "form" as parameter
function checkForm( form )
{
// Now, checking if at least one checkbox is checked [Did I say we're checking something here? :)
// Should Field names be lists[], or lists[98] and lists[99], or something else?
// MY PROBLEM IS LOCATED HERE. NONE OF THESE WORKS
// if( notChecked( form.lists98 ) & notChecked( form.lists99 ) )
// if( notChecked( form.lists[98] ) & notChecked( form.lists[99] ) )
// if( notChecked( form.lists[] ) )
{
alert( 'You should select at least one newsletter!' );
return false;
}
}
</script>
And here's my simple and basic form, for testing purposes only:
<form method="post" action="http://www.____.net/listmail/signup.php">
<input type="hidden" name="overwrite_dupes" value="1">
Subscribe to:<br>
<input type="checkbox" name="lists[]" value="98" checked> Newsletter 98<br>
<input type="checkbox" name="lists[]" value="99" checked> Newsletter 99
<input type="image" name="sup" src="send.gif" class="formElement" onclick="return checkForm(this.form)">
</form>
Thank you all in advance.
Marie
Quebec
[BTW, it is impossible to post a new topic here with Opera 9, or at least it is impossible to preview it and continue editing. I'm using FF 1.5 now]