VALUE OF A OPTION

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
sh1tzr
Forum Newbie
Posts: 1
Joined: Tue Mar 15, 2011 10:06 am

VALUE OF A OPTION

Post 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?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: VALUE OF A OPTION

Post 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.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: VALUE OF A OPTION

Post 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]
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply