我从未试图发布使用javascript创建的动态文本框来处理数据。发送到处理页面的唯一表单数据是提交按钮值。有关如何执行此操作以便通过发布正确发送所有文本框数据的任何想法吗?
页码:
<?php
if(!isset($_GET['saleid'])) {
header('location: dashboard.php');
die();
}else{
include('db_connect.php');
$saleid = mysqli_real_escape_string($mysqli, $_GET['saleid']);
}
?>
<!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" />
<title>Untitled Document</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
<script>
$(function() {
$("#date").datepicker({ dateFormat: 'yy-mm-dd' })
$(document).ready(function(){
var counter = 2;
$("#addButton").click(function () {
if(counter>5){
alert("Only 10 textboxes allow");
return false;
}
$("#sale > tbody").append("<tr><td> <label>Date:</label><br /><input type='textbox' id='date" + counter + "' ></td><td> <label>Type:</label><br /><input type='textbox' id='type" + counter + "' ></td><td> <label>Amount:</label><br /><input type='textbox' id='amount" + counter + "' ></td><td><label>Notes:</label><br /><input type='textbox' id='notes" + counter + "' ></td></tr>");
counter++;
});
$("#removeButton").click(function () {
if(counter<3){
alert("No more textbox to remove");
return false;
}
counter--;
$('#sale tr:last').remove();
})
});
});
</script>
</head>
<body>
<?php echo "Sale ID: ". $saleid; ?>
<form id="form1" name="form1" method="post" action="<?php echo "process_saletrans.php?saleid=" . $saleid; ?>">
<h2>Sale Transaction</h2>
<table id="sale" width="300" border="0" cellpadding="2">
<tr>
<td> <label>Date:</label><br />
<input type='textbox' id='date1' ></td>
<td> <label>Type:</label><br />
<input type='textbox' id='type1' ></td>
<td> <label>Amount:</label><br />
<input type='textbox' id='amount1' ></td>
<td> <label>Notes:</label><br />
<input type='textbox' id='notes1' ></td>
</table>
<input type='button' value='Add' id='addButton'>
<input type='button' value='Remove' id='removeButton'>
<p>
<input type="submit" name="submit" id="submit" value="Add Transaction" />
</p>
</form>
</body>
</html>
答案 0 :(得分:0)
我相信您遇到的问题是您使用id
而不是name
。您可以同时使用id
,但我很确定它没有设置表单字段的名称以便提交表单。