开发者

How to retrieve DropDown value when it is posted?

开发者 https://www.devze.com 2022-12-15 12:08 出处:网络
When the Form is submitted, I can ret开发者_JAVA技巧rieve the DropDown text using $_POST[\'....\']. But I want to get the DropDown value not the display member. How to get it using POST?You probably n

When the Form is submitted, I can ret开发者_JAVA技巧rieve the DropDown text using $_POST['....']. But I want to get the DropDown value not the display member. How to get it using POST?


You probably need to set a value attribute to your options, with HTML like this:

<select name="foo">
  <option value="bar">Some text</option>
</select>

your $_POST array will contain 'foo' => 'bar'.


If you’re talking about the SELECT element, the value of an option is the value of the value attribute or the content of that OPTION element itself if value is missing:

<option value="foo">bar</option> <!-- value is "foo" -->
<option>baz</option>             <!-- value is "baz" -->

So declare a value attribute for your options if you don’t want to contents to be the values of your options.


You need to specify it in the value attribute of the <option> element. E.g.

<select name="dropdownname">
    <option value="valueYouWant1">Label which is displayed 1</option>
    <option value="valueYouWant2">Label which is displayed 2</option>
    <option value="valueYouWant3">Label which is displayed 3</option>
</select>

This way the selected value (one of the valueYouWant* values) is available by $_POST['dropdownname'].

0

精彩评论

暂无评论...
验证码 换一张
取 消