Please find the below code to add new rows as well as delete row button. using that script we can enable only 5 rows after that "Add More" button automatically disable. Now the problem is, if I click on submit button php page should print all rows values. but I am not able to print all rows values as all rows name are same (input_box_one[] and input_box_two[] ). hence I am not able to get all rows.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="./jquery-1.7.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('.del').live('click',function(){
$(this).parent().parent().remove();
});
$('.add').live('click',function(){
var i = 1;
var appendTxt = "<tr><td>Pront ID:</td><td><input type='text' name='input_box_one[]' /></td><td>Pronto Title:</td> <td><input type='text' name='input_box_two[]' /></td> <td><input type='button' class='del' value='Delete' /></td></tr>";
$("tr:last").before(appendTxt);
var inputs = document.getElementsByTagName('input').length;
if(inputs == 17){
document.getElementById("countButton").disabled = true;
}
$i++
});
});
</script>
</head>
<body>
<form name="form1" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table id="options-table">
<tr>
<td>Pront ID:</td><td><input type="text" name="input_box_one[]" /></td>
<td>Pronto Title:</td><td><input type="text" name="input_box_two[]" /></td>
<td><input type="button" class='del' value='Delete' /></td>
<input type="hidden" name="count" value="<?php $i; ?>">
</tr>
<?php
echo "<tr><td><input id=\"countButton\" type=\"button\" class=\"add\" value=\"Add More\"/></td><td><input type=\"submit\" name=\"submit\" value=\"submit\"></td></tr>";
?>
</table>
</form>
</body>
</html>
Could anyone please help on this.
thanks in advance.
Editing the question:
Hi,
In the script i need to enter Pronto ID exactly 12 character. if it's less/more than 12 it should echo the message to enter 12 character. what code should i add to this line? please help me.
var appendTxt = "<tr><td>Pront ID:</td><td><input type='text' name='input_box_one[]' /></td><td>Pronto Title:</td> <td><input type='text' name='input_box_two[]' /></td> <td><input type='button' class='del' value='Delete' /></td></tr>";
foreach ($_POST['input_box_one'] as $v) {
echo $v . '<--- i am your value<br>';
}
Result
------
inputboxvalue1
inputboxvalue2
inputboxvalue3
etc....
print the $_POST varaible on php page like
<?php print_r($_POST); ?>
Than you will get the idea of posted inputs.afterword you have use the foreach method.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.