admin管理员组文章数量:1335371
Im trying to make this HTML bo box equal to a value.
<select name="file_type">
<option value=".jpg">.JPG</option>
<option value=".png">.PNG</option>
<option value=".gif">.GIF</option>
</select>
So when i select jpg on my web page, does that mean that file_type = .jpg? I'd think so.
So then im trying to call that value from javascript, like so:
var fileType = document.getElementByID("file_type").value;
is that how it is done? How else can I get the value of the selected item in the bo box?
Regards
Im trying to make this HTML bo box equal to a value.
<select name="file_type">
<option value=".jpg">.JPG</option>
<option value=".png">.PNG</option>
<option value=".gif">.GIF</option>
</select>
So when i select jpg on my web page, does that mean that file_type = .jpg? I'd think so.
So then im trying to call that value from javascript, like so:
var fileType = document.getElementByID("file_type").value;
is that how it is done? How else can I get the value of the selected item in the bo box?
Regards
Share Improve this question asked Sep 28, 2014 at 11:10 user2244896user22448961 Answer
Reset to default 4First your control has no ID
attribute set only name so you need to add the id to the html
<select id="file_type" name="file_type" >
Then the way you get the selected of a bo is like:
var selectCtrl = document.getElementById("file_type");
var selectedItem = selectCtrl.options[selectCtrl.selectedIndex];
This selectedItem
has to properties value
and text:
selectedItem.value //<-- ".jpg"
and
selectedItem.text //<-- ".JPG"
Online Demo
本文标签: javascriptHTML Combo Box selected Item39s valueStack Overflow
版权声明:本文标题:javascript - HTML Combo Box selected Item's value - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742246929a2440027.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论