Page 1 of 1

How to check the radio button checked?

Posted: Wed Sep 24, 2008 5:02 am
by kapil1089theking
I have 7 radio button in my HTML form all of them named radiobutton and in the action page I want to know which button is clicked and for that I have written in the action.php as:

Code: Select all

 
        <?php
 
for($i=0;$i<7;$i++)     {
        if($_POST["radiobutton['$i']"])
                echo $i + "no radio is pressed";
}
?>
 
its not working plz help me with the necessary code.

Re: How to check the radio button checked?

Posted: Wed Sep 24, 2008 5:24 am
by Darkzaelus
The names should be Radionbutton[]. The square brackets define it as an array.

Cheers,

Darkzaelus.

Re: How to check the radio button checked?

Posted: Wed Sep 24, 2008 5:28 am
by ramya123
no need of for loop
replace whole code with this

$_POST['radiobutton']

Re: How to check the radio button checked?

Posted: Wed Sep 24, 2008 9:09 am
by papa

Code: Select all

empty($_POST["radiobutton"]) ? $radio = "no radio is pressed\n" : $radio =  $_POST["radiobutton"][0] . " is pressed.\n";
 
echo $radio;
Maybe...