前の記事では、フォーム要素を動的に追加することについて説明しました。今回は、これらの動的に追加されたフォーム要素から送信されたデータを処理する方法について説明します!フォーム要素を動的に追加する方法を詳細に説明しません!わからない場合は、前の記事//www.vevb.com/html/200711/23/12856.htmをご覧ください。以下は、フォーム要素を動的に追加するページコードです!
コードコピーは次のとおりです。
<html>
<head>
<title>フォーム要素の動的な追加blueshine </title>
</head>
<ScriptLanguage = "JavaScript">
functionaddelement(mytype){
varmyType、temo = document.getElementById( "add");
varnewinput = document.createelement( "input");
newinput.type = mytype;
newinput.name = "input1"; //これは必須であり、処理ページで使用する必要があります!
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; center:center"> <astyle = "color:#218868;" href = "javascript:void(0)"ボックス</a> </p>
<pid = "add"> </p>
<label>
<inputtype = "submit" name = "submit" value = "submit">
</label>
<label>
<inputtype = "reset" name = "submit2" value = "reset">
</label>
</form>
</body>
</html>
以下は、データ処理ページコードです。
コードコピーは次のとおりです。
<%@言語= "vbscript" codepage = "936"%>
<
<htmlxmlns = "http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv = "content-type" content = "text/html; charset = gb2312"/>
<title>フォーム要素の動的な追加</title>
</head>
<body>
<divstyle = "font-size:13px"> <%
dimdata、arr、n
data = trim(request.form( "input1")) 'これはコードで定義されている名前属性です
arr = split(data、 "、") '分割関数を使用してデータを分割します!
Response.Write( "これは分割されていないデータ:")
Response.Write(データ)
respons.write( "<br>")
respons.write( "<br>")
Response.write( "これは、分割関数を使用して分割されたデータです:")
respons.write( "<br>")