admin管理员组文章数量:1430052
Hi I would like to convert the values of the selected options into integers. Unfortunately its not working.
Example HTML:
<label for="ausgangssprache">Ausgangssprache</label>
<select name="ausgangssprache" size="1" id="ausgangssprache"> <option value="0.78">Deutsch</option> <option value="0.78">Englisch</option> <option value="0.78" selected>Französisch</option> <option value="0.78">Spanisch</option> <option value="0.78">Italienisch</option> <option value="1.1">Arabisch</option></select>
Javascript:
var a = document.getElementById("ausgangssprache");
var ausgangssprache = a.options[a.selectedIndex].value;
I've tried with parseInt() this both, without getting the selected value, when testing via alert()
var a = parseInt(document.getElementById("ausgangssprache"));
var ausgangssprache = a.options[a.selectedIndex].value;
var a = document.getElementById("ausgangssprache");
var ausgangssprache = parseInt(a.options[a.selectedIndex].value);
Hi I would like to convert the values of the selected options into integers. Unfortunately its not working.
Example HTML:
<label for="ausgangssprache">Ausgangssprache</label>
<select name="ausgangssprache" size="1" id="ausgangssprache"> <option value="0.78">Deutsch</option> <option value="0.78">Englisch</option> <option value="0.78" selected>Französisch</option> <option value="0.78">Spanisch</option> <option value="0.78">Italienisch</option> <option value="1.1">Arabisch</option></select>
Javascript:
var a = document.getElementById("ausgangssprache");
var ausgangssprache = a.options[a.selectedIndex].value;
I've tried with parseInt() this both, without getting the selected value, when testing via alert()
var a = parseInt(document.getElementById("ausgangssprache"));
var ausgangssprache = a.options[a.selectedIndex].value;
var a = document.getElementById("ausgangssprache");
var ausgangssprache = parseInt(a.options[a.selectedIndex].value);
Share
Improve this question
edited Jul 19, 2022 at 18:27
aynber
23k9 gold badges54 silver badges68 bronze badges
asked Mar 20, 2017 at 5:26
KrystianKrystian
9875 gold badges23 silver badges53 bronze badges
2
-
2
Try
Number(a.options[a.selectedIndex].value);
– Rayon Commented Mar 20, 2017 at 5:27 - 1 Possible duplicate of How do I convert a string into an integer in JavaScript? – Max Commented Mar 20, 2017 at 5:29
1 Answer
Reset to default 4var a = parseInt(document.getElementById("ausgangssprache").value);
you can use this, unless you're doing multiple select. to not use parseInt, assign value as a int like value=3 instead of value="3"
本文标签: javascriptconvert string to integer of selected optionStack Overflow
版权声明:本文标题:javascript - convert string to integer of selected option - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745551752a2662974.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论