Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <HTML>
- <HEAD>
- <TITLE> Add/Remove dynamic rows in HTML table </TITLE>
- <script src="js/jquery.min.js" type="text/javascript"></script>
- <script type="text/javascript">
- $(document).ready(function(){
- $('#btnSubmit').click(function(){
- $.ajax({
- type: "POST",
- url: 'http://funiks.com/invoice/phonebook/submit_new_contact_multiple_ajax.php',
- data: "chkbox=" + $('#chkbox').val() + "&txtone=" + $('#txtone').val() + "&txttwo=" + $('#txttwo').val(),
- success: function(data){
- $('#status').html(data);
- $('#chkbox').val('');
- $('#txtone').val('');
- $('#txttwo').val('');
- }
- });
- });
- });
- </script>
- <SCRIPT language="javascript">
- function addRow(tableID) {
- var table = document.getElementById(tableID);
- var rowCount = table.rows.length;
- var row = table.insertRow(rowCount);
- var cell1 = row.insertCell(0);
- var element1 = document.createElement("input");
- element1.type = "checkbox";
- cell1.appendChild(element1);
- var cell2 = row.insertCell(1);
- cell2.innerHTML = rowCount + 1;
- var cell3 = row.insertCell(2);
- var element2 = document.createElement("input");
- element2.type = "text";
- cell3.appendChild(element2);
- var cell4 = row.insertCell(3);
- var element3 = document.createElement("input");
- element3.type = "text";
- cell4.appendChild(element3);
- }
- function deleteRow(tableID) {
- try {
- var table = document.getElementById(tableID);
- var rowCount = table.rows.length;
- for(var i=0; i<rowCount; i++) {
- var row = table.rows[i];
- var chkbox = row.cells[0].childNodes[0];
- if(null != chkbox && true == chkbox.checked) {
- table.deleteRow(i);
- rowCount--;
- i--;
- }
- }
- }catch(e) {
- alert(e);
- }
- }
- </SCRIPT>
- </HEAD>
- <BODY>
- <INPUT type="button" value="Add Row" onclick="addRow('dataTable')" />
- <INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" />
- <TABLE id="dataTable" width="350px" border="1">
- <TR>
- <TD><INPUT type="checkbox" name="chk[]" id="chkbox"/></TD>
- <TD> 1 </TD>
- <TD> <INPUT type="text" name="txt[]"id="txtone"/> </TD>
- <TD><INPUT type="text" name="txt1[]" "texttwo"/></TD>
- </TR>
- <button type="button" name="btnSubmit" id="btnSubmit">Submit</button>
- </TABLE>
- </BODY>
- </HTML>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement