如何在POST后检索下拉列表的文本? [英] How to retrieve the text of a drop down list after a POST?
问题描述
你好,
< SELECT name =" f_hello">
< OPTION value = ''H''> Hello< / OPTION>"
< OPTION value =''G''> Good-Bye< / OPTION>"
< / SELECT>
在上面的例子中,我可以轻松检索f_hello变量,它将在POST后包含H或G
。但我怎么能找回你好的或者
Good-Bye字符串?
谢谢,
Denis
Zorro写道:大家好,
< SELECT name =" f_hello">
< OPTION value =''H ''> Hello< / OPTION>"
< OPTION value =''G''> Good-Bye< / OPTION>"
< / SELECT>
<在上面的例子中,我可以很容易地检索f_hello变量,它将在POST后包含H或G。但我怎么能找回你好的或者再见字符串?
谢谢你,
丹尼斯
你不能自动。你必须将字符串本身作为值传递给它,或者在php处理页面上使用查找。例如:
< SELECT name =" f_hello">
< OPTION value =''Hello''> Hello< / OPTION> ;"
< OPTION value =''Good-Bye''> Good-Bye< / OPTION>"
< / SELECT> >
或者您也可以按照自己的方式保留HTML并按照以下方式执行
:
>
myvar =(
_POST [''f_hello''] ==''G'')?''再见'':''你好'';
以上代码只是查看返回的值是否为G,如果返回再见则为
。否则返回Hello。如果你有很多价值(超过两个),你可以使用像
这样的开关盒结构,所以:
switch(
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
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后检索下拉列表的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!