Jump to content

How to get value from radio button in php using id?


siddscool19

Recommended Posts

<html>
<body>
<form method=get>
<input type=radio name=gender id=male >Male</br>
<input type=radio name=gender id=female >Female</br>
<input type=submit value=Submit>
</form>
</body>
</html>
<?php
$gender=$_GET["gender"];
echo $gender
?>

 

Now i want the value of only <input type=radio name=gender id=male > ..

What coding is to be used?

 

You HAVE to add a value= to your radios otherwise they have no value

 

<input type=radio name=gender value="male" id=male >Male</br>

<input type=radio name=gender value='female" id=female >Female</br>

 

Then do this....

<?php
$gender = $_GET['gender'];
if($gender == 'male')
{
    echo 'Its a boy!!';
}
else
{
   echo 'Throw her back';
}
?>

 

Basic HTML structure and php comparison operators.

 

Nate

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.