admin管理员组文章数量:1394611
I have one drop-down menu but in that id dynamically changes in this scenario how to get selected value in dropdown using On Change function. In this drop-down id, value changes every refresh how to get particular selected value.
<select name="status" id="dropdown_status335281563" size="1" tabindex="-1" title="" style="display: none;">
<option value="1">Apple</option>
<option value="2">Grapees</option>
I have one drop-down menu but in that id dynamically changes in this scenario how to get selected value in dropdown using On Change function. In this drop-down id, value changes every refresh how to get particular selected value.
<select name="status" id="dropdown_status335281563" size="1" tabindex="-1" title="" style="display: none;">
<option value="1">Apple</option>
<option value="2">Grapees</option>
Share
Improve this question
edited Jul 28, 2019 at 13:27
Rahul
18.6k7 gold badges42 silver badges63 bronze badges
asked Mar 16, 2017 at 9:47
kanthkanth
171 gold badge1 silver badge6 bronze badges
2
- how can you select from an element that is hidden? – guradio Commented Mar 16, 2017 at 9:48
- style="display: none;" and change :( – 4b0 Commented Mar 16, 2017 at 9:48
4 Answers
Reset to default 5
$(document).ready(function() {
$(document).on("change", "select[id^='dropdown_status']", function() {
console.log($(this).val());
})
});
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select name="status" id="dropdown_status335281563">
<option value="1">Apple</option>
<option value="2">Grapees</option>
</select>
<select name="status" id="dropdown_status33523">
<option value="3">Apple 2</option>
<option value="4">Grapees 2</option>
</select>
<select name="status" id="dropdown_status3">
<option value="5">Apple 3</option>
<option value="6">Grapees 3</option>
</select>
<select name="status" id="dropdown_status99999">
<option value="7">Apple 4</option>
<option value="8">Grapees 4</option>
</select>
If I am not wrong, your id suffix to element id will change dropdown_status
this will constant.
You can take value of this as follows,
$("select[id^='dropdown_status']").val();
I hope this will help.
Try this example for example, I am taking some sample select options and I am trying to get its value, in single function.
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis./ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".dropdown_change").change(function(){
alert($(this).val());
});
});
</script>
</head>
<body>
<select name="status" id="dropdown_change" class="dropdown_change">
<option value="1">Apple</option>
<option value="2">Grapees</option>
</select>
</body>
</html>
Your dynamic number change case try this
<select name="status" id="dropdown_status335281563" size="1"
tabindex="-1" title="" onchange="getValue()">
<option value="1">Apple</option>
<option value="2">Grapees</option>
</select>
function getValue(){
alert($("select[id^='dropdown_status']").val());
}
You can get value on the basis of some other attribute of select box like below:
$("select[name='status']").change(function(){
alert($(this).val());
})
本文标签: javascriptonchange dropdown value getStack Overflow
版权声明:本文标题:javascript - onchange dropdown value get - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744095997a2590290.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论