ASP implements the instance program of dynamically adding form content

Source: Internet
Author: User
Tags modify reset split
Program | dynamic

Most of the time, when you don't know the number of forms you need, you need to be able to control the number of forms. The following two effects were collected:

  Effect 1:

<ptml><body><form name=" Form1 "><table id=" tb1 border=0> <tr><td><a "#" > Add Attachment href= ></table><input type= "hidden" name= "fjcnt" value= "1"/></form></body></ptml>< Script language= "JavaScript" > Function addfj () {var oTb = document.getElementById ("tb1"); var oTr = otb.insertrow (0); var name = "Thefilename" +document.form1.fjcnt.value; Document.form1.fjcnt.value=parseint (Document.form1.fjCnt.value) +1; Otr.insertcell (0). InnerHTML = "<input id= ' file ' name= '" +name+ "' Type=file style= ' width:400px; ' > <input Type=button > "return false; } function delfj (obj) {Obj.parentElement.parentElement.removeNode (true); return false; }</script>

[Ctrl + A ALL SELECT hint: You can modify some of the code, and then run]

  Effect 2:

<ptml><pead><style type= "Text/css" ><!--. p9{font-size:9pt; font-family: Song body}td {font-size:9pt}. TX {height:16px; width:30px; border-color:black black #000000; border-top-width:0px; border-right-width:0px; border-b ottom-width:1px; border-left-width:0px; font-size:9pt; Background-color: #eeeeee; Color: #0000FF}.tx2 {height:16px;border-top-width:0px; border-right-width:0px; border-bottom-width:1px; border-left-width:0px; font-size:9pt; Color: #0000FF; Border-left-color: #000000; Border-right-color: #000000; Border-top-color: #000000; Border-bottom-color: #000000}.bt {border-left:1px solid #C0C0C0; border-top:1px solid #C0C0C0; Border-right-width:1; Border-bottom-width:1; height:16px; width:80px; Background-color: #EEEEEE; Cursor:hand; Border-right-style:solid; border-bottom-style:solid}.tx1 {width:400; height:20px font-size:9pt; border:1px solid; Border-color:black Black #0 00000; Color: #0000FF}--></style><script LANGUage= "VBScript" >function AddFile () Dim strstr= "<table>" If not IsNumeric (Window.form1.filenum.value) Then Window.form1.filenum.value =1for I=1 to window.form1.filenum.valuestr=str& "<tr><td valign= ' middle ' >  File "&i&": </td><td><input type= ' file ' name= ' file ' &i& ' class= ' tx1 ' value size= ' ' > Save As <input type= ' text ' name= ' file ' &i& ' ' size= ' class= ' tx2 ' ></td></tr> ' Nextwindow.uptd.innerHTML =str& "</table>" End Function</script><script language= "JavaScript" ><!--function Show () {var allnum =document.form1.filenum.value;//gets a few filefor (i=0;i<allnum;i++) {alert (" Name:file "+i) of the file box;} return false;} --></script><title></title><meta http-equiv= "Content-type" CONTENT= "text/html; charset=gb2312 "></pead><body bgcolor=" #ffffff "class=" p9 "><form method=" Post "Name=" Form1 "ACTION = "savetofile.asp" enctype= "Multipart/form-data" > <table border= "0" align="Center" cellpadding= "0" cellspacing= "0" > <TR> <td><div align= "center" ><font color= "#0000 FF "size=" 5 > Save to File </FONT></DIV></TD> </TR> <TR> <td><table width= "75 0 "border=" 1 "align=" center "cellpadding=" 0 "cellspacing=" 0 "bordercolor=" #111111 "style=" Border-collapse:collapse " > <TR> <td height= "colspan=" 2 "> Upload <input name=" FileNum "class=" TX 2 "value=" 1 "size=" 4 "> Files <input type=" button "name=" button "class=" BT "value=" set "&G T </TD> </TR> <TR> <TD> <div id= "UPTD" > </DIV></TD> </TR> <TR> <td height= "colspan=" 2 "align=" middle "> <i Nput type= "button" name= "button" class= "BT" value= "See how many Boxes" > <input type= "Submit" name= "button" class= "BT" Value= " Upload ">    <input type= "Reset" name= "button" class= "BT" value= "reset" > </TD> < /tr> </TABLE></TD> </TR> </TABLE></FORM></BODY></HTML>

[Ctrl + A ALL SELECT hint: You can modify some of the code, and then run]

In ASP, dynamic forms can be submitted in the same way as normal forms. An easy way to do this is to set the name of a fixed form, and when multiple forms are submitted, the form data is automatically separated by "," and then split with split and then recycled to submit separately. As follows:

<% @LANGUAGE = "VBSCRIPT" codepage= "936"%>
<script language= "JavaScript" >
function Addtxtproductnamebox ()
{
var oTb = document.getElementById ("Tableproductname");
var oTr = otb.insertrow (0);
Otr.insertcell (0). InnerHTML = "<input name= ' txtproductname ' type= ' text ' ><input Type=button >"
return false;
}
function Deltxtproductnamebox (obj)
{
Obj.parentElement.parentElement.removeNode (TRUE);
return false;
}
</script>
<% Dim Rs3,sql3,productnamearray
If productname<> "" Then
Set Rs3=server. CreateObject ("ADODB.") RecordSet ")
Sql3= "SELECT * from Amdiproduct"
Rs3.open sql3,conn,3,2
Productnamearray=split (ProductName, ",")
For i = 0 To UBound (productnamearray)
Rs3.addnew
RS3 ("CompanyID") =companyid
RS3 ("ProductName") =productnamearray (i)
Rs3.update
Next
Rs3.close
Set rs3=nothing
End If
%>
<form name= "Form1" method= "Post" action= "" >
Products name £ º <a href= "#" > Add product Name </a>
<table id= "Tableproductname" border=0>
<tr><td> </td></tr>
</table>
<input name= "Submit" type= "submit" id= "Submit" value= "= = Submit"/>
</form>



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.