tags:

views:

49

answers:

3

When the Form is submitted, I can retrieve the DropDown text using $_POST['....']. But I want to get the DropDown value not the display member. How to get it using POST?

+2  A: 

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'.

Wim
When the DropDown is filled dynamically, how I will come to know which option was selected. In that case, how to use $_POST[' ' => ];
RPK
Same deal, just make sure that, when filling the dropdown, you also automatically fill in the `value` attributes !
Wim
They are filling, but I want to know how to call them when using $_POST.
RPK
+1  A: 

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'].

BalusC
I guess it is the Text not the Value.
RPK
I guess you have to be more clear in your question and understand the technical meanings. You think X while it is **actually** Y.
BalusC
+1  A: 

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.

Gumbo
It is there, but how to get it in $_POST?
RPK
@RPK: In my example the values would be available with the name of the `SELECT` element: `<select name="name-of-select-element"> … </select>` → `$_POST['name-of-select-element']`. So if the first option is selected, `$_POST['name-of-select-element']` is `"foo"` and `"baz"` when the second one is selected.
Gumbo
I guess you are wrong. The first line in your post is correct, but the second one is wrong.
RPK