Reputation: 1245
I have a bootstrap modal confirm pop up connected to a form submit button where I want to include the current text value displayed in a html select list as well as the selected text value of the same html select list.
For example, I have the following html select list:
<select name="test_list" id="id_test_list">
<option value="one">One</option>
<option value="two">Two</option>
<option value="three">Three</option>
<option value="four" selected="selected">Four</option>
<option value="five">Five</option>
</select>
To add the modal message to the submit button, I have the following code:
$( "#submit_buttonA" ).attr('update-confirm', 'From ' + $('#id_test_list option:selected').text() + ' to ' + $('#id_test_list').text());
The modal message is displayed as:
From One to One Two Three Four Five
How do I change the code of the 2nd text value $('#id_test_list').text() to display only the current text value of the html select list?
For example, the user has displayed the option value two (Two) in the html select list (but the selected value is still option value four).
From Four to Two
EDIT I have just realized what I have asked here! This is the effect of being sleep deprived and looking at a problem for too long and over thinking the issue. Sorry to all for asking such a deranged question.
Upvotes: 0
Views: 2043
Reputation: 14064
I am not sure what you are trying to do. but as you want the current or selected value of the select you can use
$( "#submit_buttonA" ).attr('update-confirm', 'From ' + $('#id_test_list option:selected').text() + ' to ' + $('#id_test_list').val());
Change text()
to val()
Alternatively you can also use
$('#id_test_list :selected').text();
Upvotes: 2