简单测试:多个同名的Input项如何提交数据以及如何处理
测试多个同名input处于同一form中提交数据的情况及处理办法
多个同名的input放在同一Form中,接收到的数值会是怎么样的呢?实验证明,数据将会是这样的:
在每个input的value后面,加上", ",即逗号和空格,开成一串字符串。处理这些数据时,根据需要,可以做不同的分离,例如可以将它改组成一个数组。
测试页面如下:
test.asp
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
If Request.Form("action") = "check" Then
Response.Write(Request.Form("checkbox"))
End If
If Instr(Request.Form("checkbox"),",") <> 0 Then
Dim myarr
myarr = split(Request.Form("checkbox"),", ")
For i = 0 to ubound(myarr)
response.Write("'" & myarr(i) & "'")
next
End If
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<form name="form1" method="post" action="test.asp">
<input type="checkbox" name="checkbox" value="1">
<input name="action" type="hidden" id="action" value="check">
<input type="checkbox" name="checkbox" value="2">
<input type="checkbox" name="checkbox" value="3">
<input type="checkbox" name="checkbox" value="4">
<input type="submit" name="Submit" value="提交">
</form>
</body>
</html>