devxlogo

Pass Both the Value and Text of a SELECT Control

Pass Both the Value and Text of a SELECT Control

Question:

How do I pass both the option value and option label parameter through ASP?

Answer:

Create a hidden input (text) box within the form:

Then, write code for the ONCHANGE event of the SELECT control to populate the hidden text box:

When the user chooses an option from the SELECT control, the text box will be updated with the text value of the option selected. When the form is submitted, you will obtain the value of the SELECT option from the SELECT control, while the hidden text box will give you the string label value.

In the code, “this” refers to the SELECT control itself. You are assigning the “text” property of the currently selected item (“selectedIndex”) to the “value” property of the hidden text box. You can also encapsulate the code in its own function and call the function on the ONCHANGE event.

devx-admin

Share the Post: