Forum Moderators: coopster
I KNOW how to do the if else statements, I just do not fully understand how to display certain information off of the selected radio buttons. I know I am supposed to do it in a simplistic manner, by using a variable. Because I have read that with forms you can simply reference the variable like ... "hello" would just be "$hello".
Here are the pages (shortened):
FORM PAGE THAT COLLECTS USERS CHOICE:
<html>
<head>
</head>
<body>
<?
print('<form action="chapter1b.php" method="post">
<input type="radio" name="something" value="opt11">Figure 1.1<br />
<input type="radio" name="something" value="opt12">Figure 1.2<br />
<input type="radio" name="something" value="opt13">Figure 1.3<br />
<input type="radio" name="something" value="opt14">Figure 1.4<br />
<input type="submit" value="Display" name="cmdDisplay">
</form>');
?>
</body>
</html>
RESULTS PAGE THAT DISPLAY USERS CHOICE:
<?
if ($value == $opt11)
{
print ("<h4>Figure 1.1</h4>");
} elseif($value == $opt12)
{
print ("<h4>Figure 1.2</h4>");
}else
{
print ("<h4>No selection made</h4>");
}
?>
If you can't help me/don't want to it's not the end of the world. Thanks.
I see a few problems here..
1. radio buttons normaly have the same name attribute implying they are in a group.
do you you drink milk?
<input type="radio" name="drink">yes
<input type="radio" name="drink">no
for me to allow the user to select only one I have to make each radio button part of the same group allowing them to only make one choice. The values of the three radio buttons would then be
value="yes"
value="no"
when it gets to the php page, for this particular group ,I can just check the variable $drink and see what it's value is
if ($drink == "yes")
{
print ("<h4>Figure 1.1</h4>");
} elseif($value == "no")
{
print ("<h4>Figure 1.2</h4>");
}else
{
print ("<h4>No selection made</h4>");
}
The one you had probably didn't work based on a few things
$value == $opt11
this reads, if the value of the variable $value is equal to the value of variable $opt11.
I think you mean this
if($value == "opt11") which reads, if the value of the variable $value is equal to the string opt11.
make sense? Try it out and tell me how that works, and again welcome to WebmasterWorld
lorax, I totally missed that
ryanoasis, you don't even need the print in your html page you could just go straight html, like this
<html>
<head>
</head>
<body>
<form action="chapter1b.php" method="post">
<input type="radio" name="something" value="opt11">Figure 1.1<br />
<input type="radio" name="something" value="opt12">Figure 1.2<br />
<input type="radio" name="something" value="opt13">Figure 1.3<br />
<input type="radio" name="something" value="opt14">Figure 1.4<br />
<input type="submit" value="Display" name="cmdDisplay">
</form>
</body>
</html>
it was late
I didn't figure there was any other explanation. After all, I know you know how to do this stuff. :)
Escaping quotes:
Given that he started the string with a ' rather than a ", the only thing that should need to be escaped would be any ' internal to the string. Of course, there's really no reason to use the print statement at all in this context. And I have to admit that I totally missed teh fact that there even was a print statement until Lorax pointed it out.
Okay it is how jatar_k said.
I was using the name attribute (of the group)
instead of the value attribute to check the value.
Yes I know it does not seem logic to put the whole form into a php page when its all just
html anyway.
Well now I know you use the name of the group as the variable and check the string with the
value attribute.
Thanks to all.
S'allright - I've missed obvious stuff too - and pounded my head against the wall for hours swearing the code should work only to have a coworker (or worse - someone on this Board) point out the obvious oversight. Geesh - talk about embarrasing!
In the end, a solution is achieved and that's what counts.