How to check the radio button checked?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kapil1089theking
Forum Commoner
Posts: 46
Joined: Wed May 28, 2008 1:51 pm
Location: Kolkata, India
Contact:

How to check the radio button checked?

Post 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.
Darkzaelus
Forum Commoner
Posts: 94
Joined: Tue Sep 09, 2008 7:02 am

Re: How to check the radio button checked?

Post by Darkzaelus »

The names should be Radionbutton[]. The square brackets define it as an array.

Cheers,

Darkzaelus.
ramya123
Forum Newbie
Posts: 13
Joined: Thu Sep 11, 2008 6:11 am

Re: How to check the radio button checked?

Post by ramya123 »

no need of for loop
replace whole code with this

$_POST['radiobutton']
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: How to check the radio button checked?

Post by papa »

Code: Select all

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