0

我从未尝试过发布使用 javascript 创建的动态文本框来处理数据。发送到处理页面的唯一表单数据是提交按钮值。关于如何做到这一点的任何想法,以便正确发送通过 post 发送的所有文本框数据?

页面代码:

<?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>
4

1 回答 1

0

I believe the issue you're having is that you're using id rather than name. You can use id at the same time, but I'm pretty sure it doesn't set the name of the form field for purposes of submitting the form.

于 2013-04-28T04:04:23.640 回答