Jump to content

Archived

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

siddscool19

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

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?

 

Share this post


Link to post
Share on other sites

add a value field to your buttons so one is value=male...

 

Scott.

Share this post


Link to post
Share on other sites

That i don't want to do.........

I just want that if field come from male then it accepts otherwise it doesn't accepts how to do that?

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

×
×
  • 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.