[英]How to Get data from Combo Box and Input it to Text Box with Javascript?
I have this code, it is quite simple but why isn't it working? 我有这段代码,它很简单,但是为什么不起作用?
<html>
<head>
<script type=”text/javascript“>
function Expedisi()
{
var x=document.getElementById("cmb");//this the script for get data combo box
var y = document.getElementById("txt");
getCmb = x.value;
y.value = getCmb;
alert(x);
}
</head>
<body>
<select name="JENIS" id="cmb" data-role="slider" onChange="Expedisi()">
<option value="Suplier">Sup</option>
<option value="Expedisi">Exp</option>//if i pick one of this the value will be input on text box
</select>
<input type="text" name="BKIRIM" id="txt" value=""> //this the destination value
</body>
</html>
Can anyone Helpme? 谁能帮我? because this script is not run?
因为该脚本未运行?
Thanks 谢谢
Your code is working for me. 您的代码对我有用。 Try it here.
在这里尝试。 http://jsfiddle.net/DLs7j/ That is the same exact code as yours.
http://jsfiddle.net/DLs7j/这与您的代码相同。 Copy, pasted.
复制,粘贴。
Best 最好
You don't need getCmb, and you don't need to declare an extra element. 您不需要getCmb,也不需要声明额外的元素。
Use this instead: 使用此代替:
<html>
<head>
<script type="text/javascript">
function Expedisi(t)
{
var y=document.getElementById("txt");
y.value = t.value;
}
</script>
</head>
<body>
<select name="JENIS" id="cmb" data-role="slider" onChange="Expedisi(this);">
<option value="Suplier">Sup</option>
<option value="Expedisi">Exp</option>
</select>
<input type="text" name="BKIRIM" id="txt" value=""/>
</body>
</html>
You need to change the quotes around the script type tag. 您需要更改脚本类型标记周围的引号。 You are current using the ”” instead of "";
您当前使用的是“”而不是“”; so change ”text/javascript” to "text/javascript".
因此将“ text / javascript”更改为“ text / javascript”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.