how to store values from dynamically added rows into database
-
hi to all, i have faced a problem in storing the values in the textfield created dynamically by clicking a button. the insert query in the code stores only the first value in the array that is the value from default textfield in the form not the dynamically created ones. I am using the code: var glob; glob = 1; function insert_row(tablename) { var the_table = document.getElementById(tablename); var new_row_index = the_table.rows.length; glob = glob + 1; the_table.insertRow(new_row_index); the_table.rows[new_row_index].insertCell(0); the_table.rows[new_row_index].cells[0].innerHTML =(the_table.rows[0].innerHTML); } function removeRowFromTable(tblSample) { var tbl = document.getElementById(tblSample); var lastRow = tbl.rows.length; if (lastRow > 1) tbl.deleteRow(lastRow - 1); } function removeRowFromTable(tblSample) { var tbl = document.getElementById(tblSample); var lastRow = tbl.rows.length; if (lastRow > 1) tbl.deleteRow(lastRow - 1); } function validateRow(frm) { var chkb = document.getElementById('chkValidate'); if (chkb.checked) { var tbl = document.getElementById('tblSample'); var lastRow = tbl.rows.length - 1; var i; for (i=1; i<=lastRow; i++) { var aRow = document.getElementById('txtRow' + i); if (aRow.value.length <= 0) { alert('Row ' + i + ' is empty'); return false; } } } openInNewWindow(frm); }
Text Field: *
Comments:
-
hi to all, i have faced a problem in storing the values in the textfield created dynamically by clicking a button. the insert query in the code stores only the first value in the array that is the value from default textfield in the form not the dynamically created ones. I am using the code: var glob; glob = 1; function insert_row(tablename) { var the_table = document.getElementById(tablename); var new_row_index = the_table.rows.length; glob = glob + 1; the_table.insertRow(new_row_index); the_table.rows[new_row_index].insertCell(0); the_table.rows[new_row_index].cells[0].innerHTML =(the_table.rows[0].innerHTML); } function removeRowFromTable(tblSample) { var tbl = document.getElementById(tblSample); var lastRow = tbl.rows.length; if (lastRow > 1) tbl.deleteRow(lastRow - 1); } function removeRowFromTable(tblSample) { var tbl = document.getElementById(tblSample); var lastRow = tbl.rows.length; if (lastRow > 1) tbl.deleteRow(lastRow - 1); } function validateRow(frm) { var chkb = document.getElementById('chkValidate'); if (chkb.checked) { var tbl = document.getElementById('tblSample'); var lastRow = tbl.rows.length - 1; var i; for (i=1; i<=lastRow; i++) { var aRow = document.getElementById('txtRow' + i); if (aRow.value.length <= 0) { alert('Row ' + i + ' is empty'); return false; } } } openInNewWindow(frm); }
Text Field: *
Comments:
the html - should be - and the javascript should also generate the controls with name="increment[]". If this fails then try to put the index for the control through javascript i.e. increment[0] for the first one, increment[1] for the second one .... This will result in an array of values which you can handle through the PHP script after form post.
Girish Nbr.