I have been trawling through various examples of radio buttons validation and grasp the concept but no examples seem to fit my situation. I have queried my database which has 4 options and for each option I have generated an associated radio button as below:
<?php foreach($options as $option){ ?>
<p><input type="radio" name="ID<?php echo $row['id']; ?>" value="<?php echo $option; ?>"><?php echo $option; ?></p>
<?php } ?>
So this basically generates 4 radio buttons per row called from the database. This appears in the source as:
<form method="POST" action="Result.php">
<p>1. Question </p>
<p><input type="radio" name="ID1" value="answer1">answer1</p>
<p><input type="radio" name="ID1" value="answer2">answer2</p>
<p><input type="radio" name="ID1" value="answer3">answer3</p>
<p><input type="radio" name="ID1" value="answer4">answer4</p>
<p>2. Question 2</p>
<p><input type="radio" name="ID2" value="answer1">answer1</p>
<p><input type="radio" name="ID2" value="answer2">answer2</p>
<p><input type="radio" name="ID2" value="answer3">answer3</p>
<p><input type="radio" name="ID2" value="answer4">answer4</p>
<input type="submit" name="submit" value="Submit!">
</form>
etc etc.
The names of these radio buttons are partially generated by php, how can I use javascript with an associated alert to check 1 of the radio buttons from each question has been checked prior to submitting the form the questions are populated within?
Or maybe even just how can I achieve this with php ISSET?
result.php,isset($_POST['ID1'])will return true if one of these radio buttons from the first question was checked. Then$_POST['ID1']will hold the value of either answer1, answer2 and so on.