从您的问题措辞中,我了解到您想要select classn
价值rollno text box
。如果我错了,请纠正我。
这是解决方案。
Javascript
<script>
function assingText()
{
var className = document.getElementById("classnId").value;
if(className != "select")//check if it is not the select
{
document.getElementById("rollNoId").value = className;
}
else
{
document.getElementById("rollNoId").value = ""; //it clears the value if present
}
}
</script>
您的 HTML 代码几乎没有变化
Class:
<select name="classn" id="classnId" onchange="assingText()" > //here added id and onchange event is added
<option value="select">--Select--</option>
<option value="I class">I Class</option>
<option value="II class">II Class</option>
<option value="III class">III Class</option>
</select>
RollNO:
<input type="text" name="rollno" id="rollNoId"/> //here id is assigned to textbox