Questions | Login

Top / PHP

How to get not the value but the text from a drop down box?

demo 20 Dec 2008 11:55pm
To handle a form submit i've made a php script. But if I just get the dropdowns boxes value using $post or $request it gives me a number value. This is becuase there is hundreds of possible selections and I don't want to go and give every selection a big value. Can I use php to get the actual selection that's clicked on?

Answers

demo 21 Dec 2008 12:21am
In your select element, give it a name. The option that is selected, based on the option value, will be in that selected's name variable.

For example:

<select name=dropdown>
<option value=1>blah</option>
<option value=2>blah2</option>
</select>

$dropdown will equal whatever is selected... (if registerglobals is on, if not, you have to use $_POST['dropdown']...)
demo 21 Dec 2008 12:22am
Ofcourse u can
demo 21 Dec 2008 01:06am
put the same text in "value" as you put in text!
<option value='mytext'>mytext</option>

Related

Submit Answer

You must be logged in to post an answer. Please Login or Register.

Powered by phpMyAnswers.