Reputation: 8705
I have code like this:
<select name="caffe" id="caffe">
<option value="5">Red</option>
<option value="6">nmfxnsdnx</option>
</select>
<div id="gll_select">
<script>
var caffe = $("#caffe").val();
var cff_name = $("#caffe option:first").text();
$("#gll_select").load("http://localhost/010/form/galleries", {id : caffe}, function(){
$("#gll").on('change', function(){
var cff_name = $("#caffe").text();
get_gallery(cff_name);
console.log(cff_name);
});
});
</script>
</div>
How can I get text value of the option that has been selected?
Upvotes: 1
Views: 7586
Reputation: 166031
Change this line:
var cff_name = $("#caffe").text();
To this:
var cff_name = $("#caffe option:selected").text();
This uses the :selected
selector to find the option that is selected, and then gets the text of that, rather than getting the text of the entire select
element.
Upvotes: 9