Forum Moderators: coopster

Message Too Old, No Replies

Reading a value from combobox

Getting the value from a form

         

whizzy

2:31 am on Jun 20, 2003 (gmt 0)

10+ Year Member



Hi

I'm having a small and probably stupid problem that is easy to solve but i can't get my head around to it!
After I submit the form I'm assigning the data from the form to several session variables for later storage. So far so good. When it comes to my combobox I use this:

$_SESSION['country'] = $_POST['country'];

And it works when I need to get the value from it, and in this case it is a number for each country. But I need to get the shown value in the combobox, like the name of the country. I know I can put the name of the country in the value of the box, but thats not good enough.

So how can I read the text instead of the value?

DrDoc

3:35 am on Jun 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, then your only option is to have those countries in an array, and match it against the number.

$countries = array("Sweden","Australia","Denmark","Japan");

$_SESSION['country'] = $countries[$_POST['country']];

..assuming the countries in the combo box are numbered from 0 to whatever...

whizzy

6:51 am on Jun 20, 2003 (gmt 0)

10+ Year Member



So there is no way that I can read the text in the box?
like in javascript I can do:

country.text

if i'm not too mistaken...don't feel like creating an array with 50 elements... :D

daisho

7:30 pm on Jun 20, 2003 (gmt 0)

10+ Year Member



No there is no way. The displayed text from a combo box is not returned to the server on a get or post. You only get the value that was selected.

Javascript runs on the client side and is responsible for rendering the pulldown box and is there for a javascript object which is why you can get the name value.

daisho.