How to check which radio button is selected?

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
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

How to check which radio button is selected?

Post by mjseaden »

Dear All,

I have radio buttons on a form. When I press submit, how do I determine on the receiving code which radio button has been selected, since they both have the same name? (Some PHP would be great to demonstrate!)

Many thanks

Mark
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

Post by lostboy »

If they have the same name, then you check the values

Code: Select all

$radio = $_POST['RadioButtonName'];

if ( $radio == "x" ){ 
  //do something
}else[if ($radio=="y"]){
  //do something else
}
Post Reply