|
Posted by Zorro on 03/25/06 13:33
Thanks Robert,
My problem is the drop down list is dynamically filled with a sql query so
I'd have to look up the string from the DB.
Yes, I could pass the string in the value attribute like "H:Hello" also.
I think I'll keep up with the query anyway.
Thanks for helping.
Cheers,
Denis
"rlee0001" <robeddielee@hotmail.com> a ιcrit dans le message de news:
1143282598.245858.14670@i40g2000cwc.googlegroups.com...
>
> 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
>
[Back to original message]
|