I am trying to show the selected value of a drop down, but its not selected the dropdown value, but adding another value to the dropdown list.
here is the code I am using:
jquery
var panyId = $(this).closest('tr').find('#headquarterIdForSearch').text();
var panyName = $(this).closest('tr').find('#panyNameId').text();
$(this).parents().find('.hqSelect option:selected').val(panyId).text(panyName);
The above code is not selecting the value that I am assigning to the Text and val property. However, it is adding a new property. Lets say, I have fetched value for panyName as "FIS" and panyId as 123.
The value is present under the dropdown however, it is adding a new value to the dropdown.
How can I show the selected value? I have also used the below code:
$('#dropDownId :selected').text();
Thanks,
I am trying to show the selected value of a drop down, but its not selected the dropdown value, but adding another value to the dropdown list.
here is the code I am using:
jquery
var panyId = $(this).closest('tr').find('#headquarterIdForSearch').text();
var panyName = $(this).closest('tr').find('#panyNameId').text();
$(this).parents().find('.hqSelect option:selected').val(panyId).text(panyName);
The above code is not selecting the value that I am assigning to the Text and val property. However, it is adding a new property. Lets say, I have fetched value for panyName as "FIS" and panyId as 123.
The value is present under the dropdown however, it is adding a new value to the dropdown.
How can I show the selected value? I have also used the below code:
$('#dropDownId :selected').text();
Thanks,
Share Improve this question asked Aug 25, 2016 at 9:44 Running RabbitRunning Rabbit 2,72015 gold badges55 silver badges74 bronze badges 1- 1 add your html dropdown list code – Rajkumar R Commented Aug 25, 2016 at 9:47
3 Answers
Reset to default 2
alert($('#id').val());
function demo()
{
alert($('#id').val());
}
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id='id' onchange="demo()">
<option value="1">Vijay </option>
<option value="2">Raj </option>
<option value="3">Ganesh </option>
<option value="4">Ram </option>
</select>
Try this:
<option value="one">One</option>
$('#dropDownId').val();
It will give the selected option value ie. value="one" from above code snippet.
Just use .val()
function to get the value, you don't need to pass any argument.
$(this).parents().find('.hqSelect').val()
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745420655a4626950.html
评论列表(0条)