<select name="Year" size=1 >
<%
dim i
for i=1900 to 2050
response.write "<option value=" & i & ">" & i &"</option>"
next
%>
</select>
<script language=javascript>
document.all.Year.value="<%=Year%>";
</script>
<%
dim i
for i=1900 to 2050
response.write "<option value=" & i & ">" & i &"</option>"
next
%>
</select>
<script language=javascript>
document.all.Year.value="<%=Year%>";
</script>
option里面写value不就可以了!
提交的时候,服务器端就会得到这个value值如果是检测变化,在select里面加上onchange事件通过var y = Year.options[Year.selectedIndex].value就可以获得改变复选框的value值,估计你要的是第二个吧!
jsp中:String a=request.getParameter("Year");在html中,你可以:
document.forms[0].Year.options[selectedIndex].value
得到下拉列表的值。
客户端取select可以是
xxxx=document.all.Year(document.all.Year.selectedIndex).value
<%
dim i,s
s=""
iYear=2000
for i=1900 to 2050
if iYear=i then
s=" selected "
else
s=""
end if
response.write "<option value=" & i & s & ">" & i &"</option>"
next
%>
</select>
<head>
<script language="javascript">
<!--
function test_onclick()
{
var i = document.forms[0].elements[0].selectedIndex;
alert(document.forms[0].Year.options[i].value);
}
-->
</script>
</head><body>
<form name="myForm">
<select name="Year">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<input type="button" name="test" value="test" onclick="test_onclick()">
</form>
</body>
</html>