The previous article talked about dynamically adding form elements. This time we will talk about how to handle the data transmitted from these dynamically added form elements! I won’t explain in detail how to dynamically add form elements! If you don’t understand, take a look at the previous article //www.Vevb.com/html/200711/23/12856.htm below is the page code for dynamically adding form elements!
The code copy is as follows:
<html>
<head>
<title>Dynamic addition of form elements BlueShine</title>
</head>
<scriptlanguage="javascript">
functionAddElement(mytype){
varmytype,TemO=document.getElementById("add");
varnewInput=document.createElement("input");
newInput.type=mytype;
newInput.name="input1";//This is a must, and it must be used in the processing page!
TemO.appendChild(newInput);
varnewline=document.createElement("br");
TemO.appendChild(newline);
}
</script>
<body>
<formaction="getdata.asp"method="post"name="frm">
<pstyle="background:#FFEC8B;border:solid1px#1E90FF;font-size:13px;line-height:200%;width:100px;text-align:center"><astyle="color:#218868;"href="javascript:void(0)"onClick="AddElement('text')">Add text box</a></p>
<pid="add"></p>
<label>
<inputtype="submit"name="Submit"value="submit">
</label>
<label>
<inputtype="reset"name="Submit2"value="Reset">
</label>
</form>
</body>
</html>
The following is the data processing page code:
The code copy is as follows:
<%@LANGUAGE="VBSCRIPT"CODEPAGE="936"%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312"/>
<title>Dynamic addition of form elements</title>
</head>
<body>
<divstyle="font-size:13px"><%
dimdata,arr,n
data=Trim(Request.Form("input1"))' This is the name attribute defined in the code
arr=split(data,",")' Use the Split function to split the data!
Response.Write("This is undivided data:")
Response.Write(data)
Response.Write("<br>")
Response.Write("<br>")
Response.Write("This is the data split by using the Split function:")
Response.Write("<br>")