I've the following code for the two radio buttons but it isn't working i don't know why :S

If 'On' is selected it displays 'ON is selected' and so on but it isn't working :S
and i want one button to be selected at a time but when i run this code i am able to select both the button.
what is the problem

<form method="post" action="<?php echo $PHP_SELF;?>">
	Family Filter:
	<input type="radio" name="button1" value="On" /> On
	<input type="radio" name="button2" value="Off" /> Off
	</form> 
	
	<?php
	
	if (isset($_POST['button1'])) //&& $_POST['button1'] == 'On')
	{
    echo "ON is Selected.";
	}
else if (isset($_POST['button2'])) //&& $_POST['button2'] == 'Off')
	echo "Off is selected";
	
	?>

Set the same name attribute to both input:

<input type="radio" name="button1" value="on" /> on
<input type="radio" name="button1" value="off" /> off

And in PHP side check for $_POST value, bye.

OK, it doesn't work,

here is the code

<form method="post" action="<?php echo $PHP_SELF;?>">
	Family Filter:
	<input type="radio" name="button1" value="On" onClick="submit();" /> On
	<input type="radio" name="button1" value="Off" onClick="submit();" /> Off
	</form> 
	
	<?php
	
	if (isset($_POST['button1']) == 'On')
    echo "Need wheelchair access.";
	
	else if (isset($_POST['button1']) == 'Off')
	echo "not checked";
	
	?>
Member Avatar for brewbuff

Remove isset()

if ($_POST['button1'] == 'On')

Remove isset()

if ($_POST['button1'] == 'On')

Thankyou it worked :)
but i also want the radio button to remain checked , is it possible ?

Yes:

<input type="radio" name="button1" value="On" onClick="submit();" <?php echo ($_POST['button1'] == 'On') ? 'checked="checked"' : ''; ?> /> On
	<input type="radio" name="button1" value="Off" onClick="submit();" <?php echo ($_POST['button1'] == 'Off') ? 'checked="checked"' : ''; ?> /> Off

bye!

commented: thanku xufyan +3

Thanks alot it worked :D

Thanks

you're welcome, bye! :)

use java script for radio button

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.