0

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";
	
	?>
4
Contributors
9
Replies
14
Views
5 Years
Discussion Span
Last Post by aadesh.aakash
0

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.

0

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";
	
	?>
0

Remove isset()

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

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

1

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!

Votes + Comments
thanku xufyan
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.