Link to home
Start Free TrialLog in
Avatar of keith1001
keith1001Flag for United States of America

asked on

PHP / Form get value and selection from Select Box.

I have an HTML form with a select box.  I cant figure out how to pass along the option value (index value) and also the selected name of a <SELECT> box.  I need to be able to access both via the $_POST[].  I can get the option vale but not the text of the selected option.
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

That's the way it works.  If you want the text, you have to include it in the value.
So you gonna to have a hidden field for example, and use javascript to set its value with the option's selected Text value.  By saving value into a hidden field, you should able to retrieve it after your form was posted.
This is by design because your PHP should be able to work out the text from the value of the option.  Given how easy it is to spoof data, you should do some server side validation regardless.
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of keith1001

ASKER

This what I was looking for, excellent.  Thanks for a nice clean example and other useful links!