|
Posted by rlee0001 on 03/25/06 12:29
Zorro wrote:
> Hello guys,
>
> <SELECT name = "f_hello">
> <OPTION value = 'H'>Hello</OPTION>"
> <OPTION value = 'G'>Good-Bye</OPTION>"
> </SELECT>
>
> In the case above, I can easily retrieve the f_hello variable which will
> containts H or G after a POST. But how could I retrieve the "Hello" or
> "Good-Bye" string?
>
> Thank you,
> Denis
You can't automatically. You have to either pass the string itself as
the value or use a lookup on the php processing page. For example:
<SELECT name = "f_hello">
<OPTION value = 'Hello'>Hello</OPTION>"
<OPTION value = 'Good-Bye'>Good-Bye</OPTION>"
</SELECT>
Or alternatively you can leave the HTML the way you had it and do
something like this:
$myvar = ($_POST['f_hello']=='G')?'Good-Bye':'Hello';
The above code simply looks to see if the returned value was a "G", and
if so returns "Good-Bye". Otherwise it returns "Hello". If you have
many values (more than two) you can use a switch case structure like
so:
switch ($_POST['f_hello']) {
case 'G': $myvar='Good-Bye';break;
case 'H': $myvar='Hello';break;
case 'P': $myvar='Please';break;
case 'T': $myvar='Thank You';break;
}
The best option however is to put the correct value in the value clause
in the HTML to begin with as per example 1 above. HTML does not limit
the string supplied in the value clause to only one character. Almost
any text can be present here with a few exceptions regarding special
symbols.
-Robert
Navigation:
[Reply to this message]
|