<html>
<head>
<title>提交数据</title>
</head>
<body>
<form name="myForm" action="sample06_submit.htm">
地址:
<select name="address">
<option value="beijing">北京</option>
<option value="shanghai">上海</option>
<option value="shenzhen">深圳</option>
</select>
性别:
<select name="sex">
<option value="men">男</option>
<option value="women">女</option>
</select>
<input type="submit" value="提交">
</form>
</body>
</html>
下面是处理请求的sample06_submit.htm
<html>
<head>
<title>使用Location对象属性获取提交数据</title>
<script language="javascript" type="text/javascript">
<!--
//获取Location对象的search属性值
var searchStr = location.search;
//由于searchStr属性值包括“?”,所以除去该字符
searchStr = searchStr.substr(1);
//将searchStr字符串分割成数组,数组中的每一个元素为一个参数和参数值
var searchs = searchStr.split("&");
//获得第一个参数和值
var address = searchs[0].split("=");
switch (address[1])
{
case "beijing":
document.write("您选择的地址为:北京<br>");
break;
case "shanghai":
document.write("您选择的地址为:上海<br>");
break;
case "shenzhen":
document.write("您选择的地址为:深圳<br>");
break;
}
//获得第二个参数和值
var sex = searchs[1].split("=");
switch (sex[1])
{
case "men":
document.write("您选择的性别为:男<br>");
break;
case "women":
document.write("您选择的性别为:女<br>");
break;
}
-->
</script>
</head>
<body>
</body>
</html>