Created
January 16, 2017 06:35
-
-
Save rushdimohamed09/8332996d8da6c27c496517e321386437 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<HEAD> | |
<TITLE> Add/Remove dynamic rows in HTML table </TITLE> | |
<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"; | |
element1.name="chkbox[]"; | |
cell1.appendChild(element1); | |
var cell2 = row.insertCell(1); | |
var element2 = document.createElement("input"); | |
element2.type = "text"; | |
element2.name="txt[]"; | |
element2.size = "10"; | |
cell2.appendChild(element2); | |
//cell2.innerHTML = rowCount + 1; | |
var cell3 = row.insertCell(2); | |
var element3 = document.createElement("input"); | |
element3.type = "text"; | |
element3.name = "text[]"; | |
element3.size = "10"; | |
cell3.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> | |
<form method="post" action="test1.php"> | |
<INPUT type="button" value="Add Row" onclick="addRow('dataTable')" /> | |
<INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" /> | |
<TABLE id="dataTable" class="rating" border="1"> | |
<tr> | |
<th></th> | |
<th>CORE VALUES</th> | |
<th>BEHAVIORAL DESCRIPTION</th> | |
</tr> | |
<TR> | |
<TD><INPUT type="checkbox" name="chk"/></TD> | |
<TD class="rating"><INPUT type="text" size="10" name="txt"/></TD> | |
<TD> | |
<INPUT type="text" size="10" name="text"/> | |
</TD> | |
</TR> | |
</TABLE> | |
<input type="submit" name="submit" value="submit"> | |
</form> | |
</BODY> | |
</html> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Untitled Document</title> | |
</head> | |
<body> | |
<?php | |
$arr = array(); | |
//for($i=0;$i<count($_POST['txt']);$i++) | |
for ($x=0; $x< count($_POST['txt']); $x++){ | |
$arr[$x] = $_POST['txt']; | |
echo $arr[$x]; | |
} | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment