Php Post无法正确使用JavaScript动态创建的文本框
我从未尝试过发布用javascript创建的动态文本框来处理数据。发送到处理页面的唯一表单数据是submit按钮值。如何做到这一点,使所有的文本框数据通过post发送正确的想法 页面代码:Php Post无法正确使用JavaScript动态创建的文本框,php,javascript,jquery,post,Php,Javascript,Jquery,Post,我从未尝试过发布用javascript创建的动态文本框来处理数据。发送到处理页面的唯一表单数据是submit按钮值。如何做到这一点,使所有的文本框数据通过post发送正确的想法 页面代码: <?php if(!isset($_GET['saleid'])) { header('location: dashboard.php'); die(); }else{ include('db_connect.php'); $saleid = mysqli_real_es
<?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>
无标题文件
$(函数(){
$(“#日期”).datepicker({dateFormat:'yy-mm-dd'})
$(文档).ready(函数(){
var计数器=2;
$(“#添加按钮”)。单击(函数(){
如果(计数器>5){
警报(“仅允许10个文本框”);
返回false;
}
$(“#销售>正文”)。追加(“日期:
类型:
金额:
备注:
”);
计数器++;
});
$(“#移除按钮”)。单击(函数(){
如果(counter我相信您遇到的问题是,您使用的是id
而不是name
。您可以同时使用id
,但我非常确定它不会为提交表单设置表单字段的名称。您知道如何创建它,还是在jquery和pa中提取值将这些input
元素的name
属性设置为当前正在将其id
属性设置为的相同值。您只需将id
更改为name
,但如果您将其用于样式设置,则可能还需要保留id
。Pr至少动态生成的代码不是这样的,所以…继续吧,把所有的id
s改成name
。明白了。谢谢你的帮助。