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
2010-01-02 14:05:14
When the DropDown is filled dynamically, how I will come to know which option was selected. In that case, how to use $_POST[' ' => ];
RPK
2010-01-02 14:13:18
Same deal, just make sure that, when filling the dropdown, you also automatically fill in the `value` attributes !
Wim
2010-01-02 14:14:55
They are filling, but I want to know how to call them when using $_POST.
RPK
2010-01-02 14:47:51
+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
2010-01-02 14:05:27
+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
2010-01-02 14:06:13
@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
2010-01-02 14:24:16
I guess you are wrong. The first line in your post is correct, but the second one is wrong.
RPK
2010-01-02 14:49:51