views:

28

answers:

1

I want to add a 4 sets of polls that each have around 4 radio buttons each for answers - then i would like to add an 'enter your email address' field below these polls.

Finally I would like the submit button after the email field to 'submit' the data from the polls and the email address entered - so only one submit button.

Just to make things even better, I would like some form of validation, that will not pass the form unless all 4 polls have a radio button pressed and a valid email.

All this is then to go into a MySQL database.

I have the email validation bit nailed - so thats fine.. it's the multiple polls bit thats getting me - I cannot get it to work?! Do i have to effectively add 5 forms?

Any help would be greatly appreciated.

A: 

No, you have one single form with a construct such as:

<input type="radio" name="poll2" value="answer3" id="poll2_answer3">
<label for="poll2_answer3">Rabbits</label>

And then have your JavaScript do something like:

function anyRadiosChecked (radioGroup) {
    for (var i = 0; i < radioGroup.length; i++) {
        if (radioGroup[i].checked) {
            return true;
        }
    }
    return false;
}

if (anyRadiosChecked(document.forms.myform.elements.poll2)) {
    // poll2 is OK
}
David Dorward
great thanks! But then what would be the cleanest way to add the other polls into this Javascript?
Chris Mousdale
Probably: A loop of elements['poll' + foo] (where foo is an incrementing integer) until you don't get an element back.
David Dorward