I used to validate checkbox form with a code like this:
<div>
<form action="survey.php" method="post" name="survey">
<span class="form"><input type="checkbox" name="event1" onClick="return countMarketing()">Event1</span>
<span class"form"><input type="checkbox" name="event2" onClick="return countMarketing()">Event2</span>
<span class"form"><input type="checkbox" name="event3" onClick="return countMarketing()">Event2</span>
<!-- other forms -->
</form>
</div>
And a javascript validation that is something like this (to limit the count of checkboxes checked):
function countMarketing() {
var NewCountMarketing = 0
if (document.survey.event1.checked)
{NewCountMarketing = NewCountMarketing + 1}
if (document.survey.event2.checked)
{NewCountMarketing = NewCountMarketing + 1}
if (document.survey.event3.checked)
{NewCountMarketing = NewCountMarketing + 1}
if (NewCountMarketing == 3)
{
alert('Please choose only two')
document.survey; return false;
}
}
And validation like this works. But now, say im using php to for the submission, how do i check if in JS if the name of the form is something like this:
<input type="checkbox" name="events[]" id="event1" onClick="return countMarketing()">Event1
Ive tried to change the JS to:
if (document.survey.events[].checked)
{code here}
if (document.survey.getElementByName('events[]').checked)
{code here}
if (document.survey.getElementById('event1').checked)
{code here}
But it doesnt work.. any can shed some light on me about this? thank you very much :)
document.survey["events[]"]