Dynamically add input and table row code

Source: Internet
Author: User
Tip: you can modify some code before running

<form name="form1" method="post" action="text.asp"> <table width="613" border="0" cellpadding="2" cellspacing="1" id="SignFrame"> <tr id="trHeader"> <td width="27" bgcolor="#96E0E2">Serial Number</td> <td width="64" bgcolor="#96E0E2">User name</td> <td width="98" bgcolor="#96E0E2">Email</td> <td width="92" bgcolor="#96E0E2">Landline phone</td> <td width="86" bgcolor="#96E0E2">Mobile phone</td> <td width="153" bgcolor="#96E0E2">Company name</td> <td width="57" align="center" bgcolor="#96E0E2"> </td> </tr></table><div> <input type="button" name="Submit" value="添加参与人" onClick="AddSignRow()" /> <input name='txtTRLastIndex' type='hidden' id='txtTRLastIndex' value="1" /> <input type="submit" name="button" id="button" value=" 确认提交 "> <input type=button name="button" id="button" value=" 行数集合 " onclick="var trn=SignFrame.getElementsByTagName('tr');alert('共有:'+(trn.length-1)+'行!');"></div></form> <script language="javascript">// Example: obj = findObj ("image1"); function findObj (theObj, theDoc) {var p, I, foundObj; if (! TheDoc) theDoc = document; if (p = theObj. indexOf ("? ")> 0 & parent. frames. length) {theDoc = parent.frames?theobj.substring(p;1}}.doc ument; theObjtheObj = theObj. substring (0, p);} if (! (FoundObj = theDoc [theObj]) & theDoc. all) foundObj = theDoc. all [theObj]; for (I = 0 ;! FoundObj & I <theDoc. forms. length; I ++) foundObj = theDoc. forms [I] [theObj]; for (I = 0 ;! FoundObj & theDoc. layers & I <theDoc. layers. length; I ++) foundObj = findobj(theobj,thedoc.layers? I =.doc ument); if (! FoundObj & document. getElementById) foundObj = document. getElementById (theObj); return foundObj;} // add a participant to enter the row function AddSignRow () {// read the row number of the last row, var txtTRLastIndex = findObj ("txtTRLastIndex", document); var rowID = parseInt (txtTRLastIndex. value); var signFrame = findObj ("SignFrame", document); // add line var newTR = signFrame. insertRow (signFrame. rows. length); newTR. id = "SignItem" + rowID; // add a column: No. var newNameTD = newTR. insertCell (0); // add the column content newNameTD. innerHTML = newTR. rowIndex. toString (); // add column: name var newNameTD = newTR. insertCell (1); // add the column content newNameTD. innerHTML ="<input name='txtName" + rowID + "' id='txtName" + rowID + "' type='text' size='12' />"; // Add column: email var newEmailTD = newTR. insertCell (2); // add column content newEmailTD. innerHTML ="<input name='txtEMail" + rowID + "' id='txtEmail" + rowID + "' type='text' size='20' />"; // Add column: phone var newTelTD = newTR. insertCell (3); // add column content newTelTD. innerHTML ="<input name='txtTel" + rowID + "' id='txtTel" + rowID + "' type='text' size='10' />"; // Add column: Cell phone var newMobileTD = newTR. insertCell (4); // add column content newMobileTD. innerHTML ="<input name='txtMobile" + rowID + "' id='txtMobile" + rowID + "' type='text' size='12' />"; // Add column: company name var newCompanyTD = newTR. insertCell (5); // add column content newCompanyTD. innerHTML ="<input name='txtCompany" + rowID + "' id='txtCompany" + rowID + "' type='text' size='20' />"; // Add column: delete button var newDeleteTD = newTR. insertCell (6); // add the column content newDeleteTD. innerHTML ="<div align='center' >Delete</div>"; // Push the row number to the txtTRLastIndex of the next row. value = (rowID + 1 ). toString () ;}// delete the specified row function DeleteSignRow (rowid) {var signFrame = findObj ("SignFrame", document); var signItem = findObj (rowid, document ); // Obtain the Index var rowIndex = signItem of the row to be deleted. rowIndex; // delete the signFrame row of the specified Index. deleteRow (rowIndex); // rearrange the sequence number. If no sequence number exists, this step is omitted for (I = rowIndex; I<signFrame.rows.length;i++){ signFrame.rows[i].cells[0].innerHTML = i.toString(); } }//清空列表 function ClearAllSign(){ if(confirm('确定要清空所有参与人吗?')){ var signFrame = findObj("SignFrame",document); var rowscount = signFrame.rows.length; //循环删除行,从最后一行往前删除 for(i=rowscount - 1;i >0; I --) {signFrame. deleteRow (I);} // reset the last line number to 1 var txtTRLastIndex = findObj ("txtTRLastIndex", document); txtTRLastIndex. value = "1"; // pre-add a row AddSignRow ();}}</script>
Tip: you can modify some code before running

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.