View Full Version : IF statement on Radio <input>
Neoeyal
07-18-2006, 08:26 PM
I have two Radio inputs, with the same name and different values.
I want to make in PHP an IF statement that will check if one of the Radios has been checked it will show "radio 1 checked"
else if the other one has been checked it'll show "radio 2 checked"
i don't know how to make it because the Radios has to be with the same name... how do I call them in their values ? :rolleyes:
pkcidstudio
07-18-2006, 09:40 PM
is this for a form or are you displaying this information some how "dynamicly"?
Neoeyal
07-18-2006, 10:02 PM
it's for a form...
but i can't do it in JS if that's what you meant to because i use it for an upload script that written in PHP
<input type="radio" name="r1" value="1">
<input type="radio" name="r1" value="2">
<?php echo($_POST['r1'] == 1 ? 'radio 1 checked' : 'radio 2 checked'); ?>
Neoeyal
07-18-2006, 11:28 PM
it didn't work
it shows me "radio 2 checked"
when i press both of the radios
http://www.eyal.webkit.biz/MsU/test.php
scaryguy
07-19-2006, 01:38 AM
You are supposed to use switch case instead of if statements I guess. Such like this;
$r1=$_POST['r1'];
switch ($r1) {
case 1:
echo("Selected radio button is: 1");
break;
case 2:
echo("Selected radio button is: 2");
break;
}
I hope, it helps.
edit: thanks for correcting me twey:)
Neoeyal
07-19-2006, 11:07 AM
blank page..
<?php
$_POST['r1']=$r1;
switch $r1 {
case 1:
echo("Selected radio button is: 1");
break;
case 2:
echo("Selected radio button is: 2");
break;
}
?>
<input type="radio" name="r1" value="1">
<input type="radio" name="r1" value="2">
http://www.eyal.webkit.biz/MsU/test.php
$_POST['r1']=$r1;
switch $r1 {
case 1:
echo("Selected radio button is: 1");
break;
case 2:
echo("Selected radio button is: 2");
break;
} Errrr... no. I don't think that'll even run: there need to be brackets around $r1 for the switch statement. If it does, neither case will fire. $r1 is never defined, and so considered null. Since you set $_POST['r1'] to that empty value, $_POST['r1'] is also null after the first line.
Neoeyal: Note that my code was for a POST form. If you're using a GET form, you should change all instances of $_POST to $_GET.
Neoeyal
07-19-2006, 08:38 PM
thanks =]
now another question:
I have a script for upload files
how can i make the "resize image" like http://imageshack.us ?
with the choose box and if the size of the image i chose to upload is less than the size i chose to resize it won't resize the image
how can I make all of this?
Haha, now you're getting into stuff I know less about :)
I suggest you read the documentation on the gd (http://www.php.net/gd) image-manipulation library, but it's definitely not a task for beginners. djr33's quite good with that stuff; maybe he'll help out if he reads this.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.