实现点击按钮从弹出的列表中选择值自动填入表单中的输入框

在表单的输入框边上有一个选择按钮,点击之后,可以弹出一个选择列表,选择某一个值之后,关闭列表,该值自动填到表单的输入框中

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>

</head>

<script language="JavaScript">

function doSel(){

document.getElementById("text1").value = showModalDialog("popup.html");

}

</script>

<body>

<input type="text" id="text1" value="">

<input type="button" value="select" onclick="doSel();">

</body>
</html>

popup.html

 

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<script language="JavaScript">
function doRet(){
window.returnValue = document.getElementById("sel").value;
close();
}
</script>
<body>
<select id="sel" value="">
<option value="AAAA">AAAA</option>
<option value="BBBB">BBBB</option>
<option value="CCCC">CCCC</option>
<option value="DDDD">DDDD</option>
<option value="EEEE">EEEE</option>
</select>
<br>
<input type="button" value="ok" onclick="doRet();">
</body>
</html>

Related Post

发表回复