i have a set of radio buttons generated inside a loop then i append a variable from the loop to the name of the radio button and to the value. the question is, how do i get the value of the radio button being selected. here's a short code..
<?php
for($i=1; $i<=5; $i++){
echo "<input type = 'radio' name=q$i value = \'$i\'>";
}
?>
How do you get the value of the radio group?
The VALUE attribute of the SELECTED radio option is carried over as part of the POST data:
e.g. when the form is submitted, $_POST['radioname'] would have a value equal to the VALUE of the radio option that was selected.
In order to work well, all the input elements must be given the same NAME; to identify each option uniquely, use an ID attribute.
To use your example:
-
<?php
-
for($i=1; $i<=5; $i++){
-
echo "<input type = 'radio' name='q' id='q$i' value = \'$i\'>";
-
}
-
?>
After submitting the form, $_POST['q'] would have a possible value of 1-5, depending on the option selected.
Please, let me know if this helps.
Regards,
Ifedi.