admin管理员组文章数量:1318156
This is my little program, what could i do for take the bobox value??
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ".dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="NewFile.css">
<title>Insert title here</title>
<script type="text/javascript">
function calcola(){
var op = String(document.getElementById("bo").value);
alert(op);
}
</script>
</head>
<body>
<div class="in">
Inserire il primo numero:
<input type="text" id="primo">
<br>
Inserire il secondo numero:
<input type="text" id="secondo">
</div>
<div class="in">
<select id="bo">
<option selected="selected">*</option>
<option>/</option>
<option>+</option>
<option>-</option>
</select>
</div>
<div>
<input type="button" name="bottone" value="Premi" onclick="calcola();">
</div>
</body>
</html>
This program should be a calculator, but I omitted most of code because it's necessary to know the operator befor doing calculations.
This is my little program, what could i do for take the bobox value??
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="NewFile.css">
<title>Insert title here</title>
<script type="text/javascript">
function calcola(){
var op = String(document.getElementById("bo").value);
alert(op);
}
</script>
</head>
<body>
<div class="in">
Inserire il primo numero:
<input type="text" id="primo">
<br>
Inserire il secondo numero:
<input type="text" id="secondo">
</div>
<div class="in">
<select id="bo">
<option selected="selected">*</option>
<option>/</option>
<option>+</option>
<option>-</option>
</select>
</div>
<div>
<input type="button" name="bottone" value="Premi" onclick="calcola();">
</div>
</body>
</html>
This program should be a calculator, but I omitted most of code because it's necessary to know the operator befor doing calculations.
Share Improve this question asked May 26, 2013 at 19:05 giaotbgiaotb 6074 gold badges10 silver badges24 bronze badges 1- What is the problem? jsbin./oduqop/1 – Musa Commented May 26, 2013 at 19:08
2 Answers
Reset to default 4Try this
function calcola()
{
var element = document.getElementById("bo");
var op = element.options[element.selectedIndex].value;
alert(op);
}
Inside your function:
function calcola(){
var elt = document.getElementById("bo"),
op = elt.options[elt.selectedIndex].text;
alert(op);
}
Buon lavoro collega italiano ;)
本文标签: Retrieve combobox value in javascriptStack Overflow
版权声明:本文标题:Retrieve combobox value in javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742042501a2417613.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论