| | |
Add/Remove rows from Table
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
Hello Frndz i m in complete mess...
i have to a table with Add/Remove rows features...
it should look like this -
after clicking the add button Row will append and Disable the textbox with values...!!!
It looks like this after clickin Add Button..
Any Help will be appriciated..!!
i have to a table with Add/Remove rows features...
it should look like this -
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
textbox1 | textbox2 | Add Button
after clicking the add button Row will append and Disable the textbox with values...!!!
It looks like this after clickin Add Button..
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
textbox1 disabled | textbox1 disabled | Edit/Delete button textbox2 | textbox2 | Add Button
Any Help will be appriciated..!!
Last edited by nish123; Jun 30th, 2009 at 6:03 am.
please Check my thread which will give you idea that how to show edit and delete Button for all records. and Last code of the thread show the dtat in textfields and u can update each recodrd,
if helpful then mark thread as Solved.
Here is a link
http://www.daniweb.com/forums/thread199644.html
if helpful then mark thread as Solved.
Here is a link
http://www.daniweb.com/forums/thread199644.html
Ayesha
•
•
Join Date: Jun 2009
Posts: 49
Reputation:
Solved Threads: 3
Here you are the code: But! What will you do with the data after the formula is fulfilled? Is the data to be processed at the same page using another JavaScript? or there have to be a button for sending the data to a process page?
You asked for the change the button "add" into the "edit". What will you do after you'll be finished with the row editing? Could not be the "ed" button change into the "lock" button while editing the row?
Think it over, before you start to code and asking the help!
HTML Syntax (Toggle Plain Text)
<HTML><HEAD> <META http-equiv="content-type" content="text/html; charset=UTF-8"> <TITLE>add/ed/del row</TITLE> <script> function add(oRow) { oRow.parentNode.replaceChild(oRow.cloneNode(true ),oRow.parentNode.insertRow(oRow.rowIndex+1)); var inpN = oRow.nextSibling.getElementsByTagName('input'); var inpR = oRow.getElementsByTagName('input'); for(var i=0;i<inpR.length;i++) { if(inpN[i].disabled)inpN[i].disabled=false; if(inpR[i].type=='text')inpR[i].disabled=true; if(inpR[i].value=='add')inpR[i].value='ed'; }; } function ed(oRow) { var inpR = oRow.getElementsByTagName('input'); for(var i=0;i<inpR.length;i++) { inpR[i].disabled=false; } } </script> </HEAD> <BODY><form method="post" action="./finalPage.php"> <table><tbody><tr><td><input type="text" name="row[txt1][]"></td><td><input type="text" name="row[txt2][]"></td><td><input type="button" value="add" onClick="(this.value=='add')?add(this.parentNode.parentNode):ed(this.parentNode.parentNode)"></td><td><input type="button" value="del" onClick="this.parentNode.parentNode.parentNode.deleteRow(this.parentNode.parentNode.rowIndex)" disabled="true"></td></tr></tbody></table> </form><br> </BODY> </HTML>
You asked for the change the button "add" into the "edit". What will you do after you'll be finished with the row editing? Could not be the "ed" button change into the "lock" button while editing the row?
Think it over, before you start to code and asking the help!
•
•
Join Date: Jun 2009
Posts: 49
Reputation:
Solved Threads: 3
As I am takinkg off the Internet, I drop down here the revised code: Save the page as the fuj.php and it shows you what you had input before send (if you have PHP module enabled on your server, of course).
See you after some hours :-)
HTML Syntax (Toggle Plain Text)
<HTML><HEAD> <META http-equiv="content-type" content="text/html; charset=UTF-8"> <TITLE>add/ed/del row</TITLE> <script> function add(oRow) { oRow.parentNode.replaceChild(oRow.cloneNode(true ),oRow.parentNode.insertRow(oRow.rowIndex+1)); // var inpN = oRow.nextSibling.getElementsByTagName('input'); var inpR = oRow.getElementsByTagName('input'); for(var i=0;i<inpR.length;i++) { if(inpR[i].disabled)inpR[i].disabled=false; if(inpR[i].type=='text')inpR[i].disabled=true; if(inpR[i].value=='add')inpR[i].value='ed'; }; } function ed(oBut) { var inpR = oBut.parentNode.parentNode.getElementsByTagName('input'); for(var i=0;i<inpR.length;i++) { if(oBut.value=='ed' && inpR[i].type=='text')inpR[i].disabled=false; if(oBut.value=='lock' && inpR[i].type=='text')inpR[i].disabled=true; } if(oBut.value=='ed'){oBut.value='lock'}else{oBut.value='ed'} } function send(oForm) { var inpF = oForm.getElementsByTagName('input'); for(var i=0;i<inpF.length;i++) { inpF[i].disabled=false; } oForm.submit(); } </script> </HEAD> <BODY><form method="post" action="./fuj.php"> <table><tbody><tr><td><input type="text" name="row[txt1][]"></td><td><input type="text" name="row[txt2][]"></td><td><input type="button" value="add" onClick="(this.value=='add')?add( this.parentNode.parentNode ):ed(this) "></td><td><input type="button" value="del" onClick="this.parentNode.parentNode.parentNode.deleteRow( this.parentNode.parentNode.rowIndex )" disabled="true"></td></tr></tbody></table> <br><input type="button" value="send" onClick="send(this.form)"> </form><br> <?php print_r($_POST["row"])?> </BODY> </HTML>
See you after some hours :-)
•
•
•
•
As I am takinkg off the Internet, I drop down here the revised code:Save the page as the fuj.php and it shows you what you had input before send (if you have PHP module enabled on your server, of course).HTML Syntax (Toggle Plain Text)
<HTML><HEAD> <META http-equiv="content-type" content="text/html; charset=UTF-8"> <TITLE>add/ed/del row</TITLE> <script> function add(oRow) { oRow.parentNode.replaceChild(oRow.cloneNode(true ),oRow.parentNode.insertRow(oRow.rowIndex+1)); // var inpN = oRow.nextSibling.getElementsByTagName('input'); var inpR = oRow.getElementsByTagName('input'); for(var i=0;i<inpR.length;i++) { if(inpR[i].disabled)inpR[i].disabled=false; if(inpR[i].type=='text')inpR[i].disabled=true; if(inpR[i].value=='add')inpR[i].value='ed'; }; } function ed(oBut) { var inpR = oBut.parentNode.parentNode.getElementsByTagName('input'); for(var i=0;i<inpR.length;i++) { if(oBut.value=='ed' && inpR[i].type=='text')inpR[i].disabled=false; if(oBut.value=='lock' && inpR[i].type=='text')inpR[i].disabled=true; } if(oBut.value=='ed'){oBut.value='lock'}else{oBut.value='ed'} } function send(oForm) { var inpF = oForm.getElementsByTagName('input'); for(var i=0;i<inpF.length;i++) { inpF[i].disabled=false; } oForm.submit(); } </script> </HEAD> <BODY><form method="post" action="./fuj.php"> <table><tbody><tr><td><input type="text" name="row[txt1][]"></td><td><input type="text" name="row[txt2][]"></td><td><input type="button" value="add" onClick="(this.value=='add')?add( this.parentNode.parentNode ):ed(this) "></td><td><input type="button" value="del" onClick="this.parentNode.parentNode.parentNode.deleteRow( this.parentNode.parentNode.rowIndex )" disabled="true"></td></tr></tbody></table> <br><input type="button" value="send" onClick="send(this.form)"> </form><br> <?php print_r($_POST["row"])?> </BODY> </HTML>
See you after some hours :-)
Bravo Maan... exactly wht i looking for... but still there are few validation tht i want in it.... Can u guide me little bit...!!!
i will be thankful to u...!!!
Validation are like this-
1) At least one row and only one row should be Fillled before adding a new row..!!!Value must be integers..!!
2)At the bottom of table there are two textboxes which total the amount of textboxes in Table..!!
3)When Edit button is pressed then add button should be hide...until the row is updated...!!!
4) After update and delete total amount should be update..
Last edited by nish123; Jun 30th, 2009 at 12:43 pm.
•
•
Join Date: Jun 2009
Posts: 49
Reputation:
Solved Threads: 3
Hi, it could be very useful, if you first wrote a simple HTML skeleton of the page even free of the scripts and features, but with the fully unique named items and/or with id. Than it could be much more simple to explain, what is the goal of the programming the features.
Here you are the page, and try to use it not for simple copy/pasting but for learning.
As I do not use MSIE I definitely cannot find out why Exploder does not show it.
Here you are the page, and try to use it not for simple copy/pasting but for learning.
As I do not use MSIE I definitely cannot find out why Exploder does not show it.
•
•
•
•
Hi, it could be very useful, if you first wrote a simple HTML skeleton of the page even free of the scripts and features, but with the fully unique named items and/or with id. Than it could be much more simple to explain, what is the goal of the programming the features.
Here you are the page, and try to use it not for simple copy/pasting but for learning.
As I do not use MSIE I definitely cannot find out why Exploder does not show it.
but sir i said only one text box from a row should be filled not both the fields...!!!
and there is one more field in which i m using dropdown and data coming from database...!!
another flaws i found tht when i edit a row..add button got disable and new lock button came in place of edit....but instead of edit if i delete the row... Add button still remain disable...!!!! i hpoe u got my point
but still its a gr8 function.....!!!!!
This javascript function i used for my work but it has lot of flaws..!!
javascript Syntax (Toggle Plain Text)
function addRowToTable() { // alert(document.getElementById('tblSample').getElementsByTagName('tr').length); var tbl = document.getElementById('tblSample'); var lastRow = tbl.rows.length; // if there's noheader row in the table, then iteration = lastRow + 1 var iteration = lastRow; var iteration1 = parseInt(lastRow+1); alert(iteration1); //Validate for empty check // var iteration = parseFloat(iteration-1); for(var i=3;i<=iteration1;i++) { if($('debit'+i)!=null) { if($('debit'+i).value.trim() == '' && $('credit'+i).value.trim() != '') { $('debit'+i).readOnly = true; $('credit'+i).readOnly = true; $('dledger'+i).disabled = true; } else if($('credit'+i).value.trim() == '' && $('debit'+i).value.trim() != '') { $('credit'+i).readOnly = true; $('debit'+i).readOnly = true; $('dledger'+i).disabled = true; } } } var debitTotal = 0; var creditTotal = 0; if($('debit'+iteration).value.trim() == '' && $('credit'+iteration).value.trim() == '') { alert('Please enter debit/credit value'); return false; } if($('debit'+iteration).value != '' && $('credit'+iteration).value != '') { alert('Please enter only debit/credit value'); return false; } for(var i=3;i<=iteration1;i++) { if($('debit'+i).value != ''){ debitTotal = parseFloat(debitTotal) + parseFloat($('debit'+i).value); } if($('credit'+i).value != ''){ creditTotal = parseFloat(creditTotal) + parseFloat($('credit'+i).value); } } $('tdebit').value = debitTotal; $('tcredit').value = creditTotal; document.getElementById('counter').value=iteration-3; var row = tbl.insertRow(lastRow); row.id = 'tr_'+iteration1; // left cell // cellRightSel.appendChild(sel); // right cell var cellRightSel = row.insertCell(0); var sel = document.createElement('select'); sel.id ='dledger' + iteration1; sel.name ='dledger' + iteration1; cellRightSel.align = 'center'; sel.style.width = 125; //sel.size = 100; <? $userid = $_SESSION['userid']; $sql="SELECT * from 0_ledger where group_id not in(1,7) and user_id = $userid"; $result=mysql_query($sql)or die('Query error:'.''.mysql_errno()); $counter=0; while($row=mysql_fetch_array($result)) {?> sel.options[<?= $counter; ?>] = new Option('<?= $row['ledgerName']?>', '<?=$row['ledger_id']?>'); <? $counter = $counter + 1; }?> cellRightSel.appendChild(sel); var cellRight = row.insertCell(1); cellRight.align = 'center'; var el = document.createElement('input'); el.type = 'text'; el.name = 'debit' + iteration1; el.id = 'debit' + iteration1; el.size = 20; el.maxLength = 8; cellRight.appendChild(el); /* var cellRightSel = row.insertCell(2); var sel = document.createElement('select'); sel.name = 'selRow' + iteration; sel.options[0] = new Option('text zero', 'value0'); sel.options[1] = new Option('text one', 'value1'); cellRightSel.appendChild(sel); */ var cellRight2 = row.insertCell(2); cellRight2.align='center'; var el2 = document.createElement('input'); el2.type = 'text'; el2.name = 'credit' + iteration1; el2.id = 'credit' + iteration1; el2.size = 20; el2.maxLength = 8; cellRight2.appendChild(el2); var cellLeft = row.insertCell(3); cellLeft.align = 'center'; cellLeft.id = 'td'+iteration1; var chbk1 = document.createElement('span'); chbk1.id = 'change'+iteration1; var chbk = document.createElement('input'); chbk.type = 'button'; chbk.name = 'additem'+iteration1; chbk.id = 'additem'+iteration1; chbk.className = 'ajaxsubmit'; chbk.value = 'Add Item'; //chbk.disabled = true; //.onClick = function(){addRowToTable();}; chbk.onclick = function(){addRowToTable1();change();}; //chbk.setAttribute('onClick','addRowToTable1();change()'); cellLeft.appendChild(chbk1); cellLeft.appendChild(chbk); }
Last edited by nish123; Jul 1st, 2009 at 4:06 am.
![]() |
Similar Threads
- DataGridView not reflecting changes to DataTable (C#)
- Add / remove table row. javascript (JavaScript / DHTML / AJAX)
- How to swap two rows of a table in a database using php (PHP)
- How do I add up all values of rows in a table??? (PHP)
- Add remove rows javascript problem.... (JavaScript / DHTML / AJAX)
- Cannot Access Control Panel or Add/Remove Programs!!! (Viruses, Spyware and other Nasties)
- Cant add/remove win components (Windows NT / 2000 / XP)
- Windows 2000 Add/Remove programs don't work... (Windows NT / 2000 / XP)
- Add or Remove Programs... Removed? (Windows NT / 2000 / XP)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: validation of Multiple forms in single page
- Next Thread: Enter text into newly created dynamic text box
| Thread Tools | Search this Thread |
acid2 ajax ajaxexample ajaxjspservlets array beta box browser captchaformproblem cart child class close codes column css date debugger decimal dependent design disablefirebug dom download editor element embed engine enter error events explorer ext file firefox focus form forms frameworks getselection google gwt gxt hiddenvalue highlightedword hint html htmlform ie7 ie8 iframe index java javascript javascripthelp2020 jquery jsf jsp jump libcurl listbox maps masterpage math media menu microsoft mimic mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent paypal pdf php player position post problem programming prototype redirect safari scale scriptlets scroll search security select software toggle unicode variables w3c web window windowofwords \n





