Page 1 of 1

VALUE OF A OPTION

Posted: Tue Mar 15, 2011 10:11 am
by sh1tzr
Hi there I have been at this now for 6 hours and no luck

I have a dynamically spawned <option> list however AJAX is using the <option value="this">

I want to post the contents of the option into the database, however I need to somehow post the option text instead of the option value ( as it contains a usless id only good for the AJAX working )

Is there a way I can post the option text into the DATABASE instead of the option value?

Re: VALUE OF A OPTION

Posted: Tue Mar 15, 2011 10:28 am
by John Cartwright
Not sure how to do it in javascript alone, but with jQuery you could easily do:

Code: Select all

var selected = $("#your_select_id option:selected");    

alert(selected.text());
Moved to Javascript.

Re: VALUE OF A OPTION

Posted: Tue Mar 15, 2011 10:48 am
by AbraCadaver
1. Change the value to use the month text which will require changing the javascript, or
2. Change the value to id so there is no value and use the id in the javascript, or
3. Create a function that is fired onsubmit() that reassigns the text to the value:

[text]select.options[select.selectedIndex].value = select.options[select.selectedIndex].text;[/text]