首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

select控件和input控件联动的有关问题

2012-03-01 
select控件和input控件联动的问题要求简单,就是把select中选择的值现实在input文本框中html代码formname

select控件和input控件联动的问题
要求简单,
就是把select中选择的值现实在input文本框中

html代码
<form   name= " ">
<input   name= "y "> </input>
<div   id= "y "> test </div>
<select   name= "X ">
<option   selected> teSt# </option>
</select>
</form>



[解决办法]
<html xmlns= "http://www.w3.org/1999/xhtml " >
<head runat= "server ">
<title> 无标题页 </title>
<script language= "javascript " type= "text/javascript ">
<!--
function setvalue()
{
var txt = document.getElementById( "testtext ");
var sel = document.getElementById( "sel ");
txt.value = sel.options[sel.selectedIndex].text;
}
-->
</script>
</head>
<body>
<form id= "form1 " runat= "server " action= "Default2.aspx ">
<div>
<input type= "text " id= "testtext " />
<select id= "sel " onchange= "javascript:setvalue(); ">
<option value= "1 "> aaa </option>
<option value= "2 "> bbb </option>
<option value= "3 "> ccc </option>
</select>
</div>
</form>
</body>
</html>

热点排行