admin管理员组文章数量:1316980
I'm new in JavaScript.. Here is my question.. I have drop down list :
<div class="spanNav-row" id="spanNav-row">
<select name="timeDropList">
<option value="6">6</option>
<option value="10">10</option>
<option value="15">15</option>
<option value="30">30</option>
<option value="60" selected>60</option>
<option value="Vac">Vacation</option>
</select>
</div>
and I have a switch :
switch () {
case 6:
break;
case 10:
break;
case 15:
break;
case 30:
break;
case 60:
break;
default:
break;
}
How do you transfer values of drop down list to the switch?
I'm new in JavaScript.. Here is my question.. I have drop down list :
<div class="spanNav-row" id="spanNav-row">
<select name="timeDropList">
<option value="6">6</option>
<option value="10">10</option>
<option value="15">15</option>
<option value="30">30</option>
<option value="60" selected>60</option>
<option value="Vac">Vacation</option>
</select>
</div>
and I have a switch :
switch () {
case 6:
break;
case 10:
break;
case 15:
break;
case 30:
break;
case 60:
break;
default:
break;
}
How do you transfer values of drop down list to the switch?
Share Improve this question edited Jul 10, 2011 at 18:39 Lance Roberts 22.9k32 gold badges114 silver badges132 bronze badges asked Jul 10, 2011 at 18:25 SergioSergio 5293 gold badges12 silver badges26 bronze badges 1- Demos: jsfiddle/userdude/PCGjU You'll need to have either Chrome Console or Firefox Firebug console open to see output. – Jared Farrish Commented Jul 10, 2011 at 18:40
3 Answers
Reset to default 6Standard JS:
var ddl = document.getElementById("timeDropList");
var selectedValue = ddl.options[ddl.selectedIndex].value;
switch (selectedValue) {}
jQuery (in case you're interested):
switch($('#timeDropList option:selected').val()) {}
NOTE: To reference the drop down by getElementById(), timeDropList will also have to be the ID, not just the name:
<select id="timeDropList" name="timeDropList">
var swi_var = document.getElementById('spanNav-row').value;
swi_var
can go in the switch
If you use jQuery, it would be piece a cake:
var selectedValue = $('#spanNav-row').val();
switch (selectedValue) {
// Your switch body here.
}
本文标签: htmlSwitch and Select in JavaScriptStack Overflow
版权声明:本文标题:html - Switch and Select in JavaScript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742017884a2414116.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论