Reputation: 916
There is a JQuery plugin I am using that shows a list of countries and states, its select option tag is like this:
<option value='US'>United States</option>
and when I submit it, I want it to POST(no ajax) "United States" instead of "US" - but I cannot find a good solution online ... anyone has any ideas?
PS. This is the plugin : http://bootstrapformhelpers.com/state/
PS. Final Solution:
Upvotes: 1
Views: 59
Reputation: 8597
Considering this has been tagged as JQuery, here's a JQuery solution... you can retrieve the inner text of an option element by using
$("#list option:selected").text();
as well as
$("#list option[value='US']").text()
As you have not addressed the issue fully, if you are doing a POST request to the server using a form, you can create a hidden input on the form, and when values are changed you can append the results of that to the hidden field using the above code.
Edit: To make it 'automatic':
$("#list").change(function(){
// Set the hidden field here with selected option
})
Edit: It appears the plugin also has a change event which relies on JQuery (why? I don't know..)
$('#list').on('change.bfhselectbox', function () {
// Set the hidden field here too if you wish...
});
Upvotes: 3