admin管理员组文章数量:1426192
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()
本文标签: javascriptHow to get the selected value of a drop down in jqueryStack Overflow
版权声明:本文标题:javascript - How to get the selected value of a drop down in jquery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745420654a2657886.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论