Core code:
<title>asp batch addition modification and deletion operation example</title><%if request.Form(op)=update then' form submission ids=request.Form(ids) if ids<> then response.Write id of the data to be deleted Collection: &ids&<br> '============ Database deletion operation conn.execute(delete from xxx where id in(&ids&))' Pay attention to doing security verification by yourself. Assuming that id is a number collection, you can make regular RegExp judgment by yourself Validity, pattern is ^/d+(,/d+)*$ end if rows=request.Form(name).count', including added/modified for i=1 to rows' traversal of each row of data id=request.Form(id).item(i)& name=request.Form(name).item(i) sex=request.Form(sex).item(i) age=request. Form(age).item(i) addr=request.Form(addr).item(i) if id<> then'Modify the operation, if id is a number plus isnumeric judgment response.Write To modify the data line: &id&|&name&| &sex&|&age&|&addr&<br> 'Modify operation else' Add operation response.Write To add data row: &name&|&sex&|&age&|&addr&<br> 'Add operation end if nextend if %><form method=post onsubmit=return check(this)><input type=hidden name=ids /><!-- Used to store the id collection to delete the record--><input type=hidden name=op value=update /> <table border=1 id=tb ><tr><th>Name</th><th>Gender</th><th>Age</th><th>Address</th><th>Delete</ th></tr><!------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- tr><td><input type=text value=name1 name=name /></td><td><input type=text value=gender1 name=sex /></td><td><input type=text value=age1 name=age /></td><td><input type=text value=address1 name =addr /></td><td><input type=button value=delete onclick=removeRow(this) /><input type=hidden name=id value=1/></td></tr><tr ><td><input type=text value=name2 name=name /></td><td><input type=text value=gender2 name=sex /></td><td><input type=text value=age2 name=age /></td><td><input type=text value=address2 name=addr /></td><td ><input type=button value=Delete onclick=removeRow(this) /><input type=hidden name=id value=2/></td></tr><!------------To be modified End of data example --------><tr><td colspan=5 align=center><input type=submit value=submit/> <input type=button value=add new data row onclick=addRow() /></td></tr></table></form><script type=text/javascript> function removeRow(btn){ if (confirm('Confirm to delete? ! ')) { var tr=btn.parentNode.parentNode; var id = btn.nextSibling;//Note that there is no space between the delete button and the hidden control of id, or nextSibling is a blank node if (id) under standard browsers .value != '') {//Delete is an existing row rather than a new one, then the id is stored in ids btn.form.ids.value += (btn.form.ids.value == '' ? ' ' : ',') + id.value; } tr.parentNode.removeChild(tr); } } function addRow() { var tb = document.getElementById('tb'), tr = tb.insertRow(tb.rows.length - 1),td=tr.insertCell(0); td.innerHTML = '<input type=text name=name />'; td = tr.insertCell(1); td.innerHTML = '<input type=text name=sex />'; td = tr.insertCell(2); td.innerHTML = '<input type=text name=age /> '; td = tr.insertCell(3); td.innerHTML = '<input type=text name=addr />'; td = tr.insertCell(4); td.innerHTML = '<input type=button value=delete onclick=removeRow(this) /><input type=hidden name=id /> ';//Add new data line id is empty} function check(f) { var tb = document.getElementById('tb'), ipts; for (var i = 1, j = tb.rows.length - 1; i < j; i++) {//Input verification, remove the first row table header and last row operation ipts = tb.rows[i].getElementsByTagName('input'); if (ipts[0].value == '') { alert('Please enter your name! '); ipts[0].focus(); return false; } if (ipts[1].value == '') { alert('Please enter gender!'); ipts[1].focus(); return false; } if (ipts[2].value == '') { alert('Please enter age!'); ipts[2].focus(); return false; } if (ipts[3].value == '') { alert('Please enter the address!'); ipts[3].focus(); return false; } } } }</script>