Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/427.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 一种形式的多个产品_Javascript_Php_Jquery_Html_Forms - Fatal编程技术网

Javascript 一种形式的多个产品

Javascript 一种形式的多个产品,javascript,php,jquery,html,forms,Javascript,Php,Jquery,Html,Forms,我想在我的表单中添加一个功能,用户可以在点击提交按钮之前添加尽可能多的条目,就像“添加到购物车”功能一样,在同一页面中显示添加的条目,在一个单独的div和submit按钮中,然后使用该提交按钮将这些多个条目保存在数据库中(在一个单独的div中,显示添加的条目) 到目前为止,我的表单只允许每次提交的条目,这意味着如果用户想要添加其他条目,他/她必须返回表单并添加,然后单击再次提交 <form method="POST" name="myForm" action="saveto.php">

我想在我的表单中添加一个功能,用户可以在点击
提交按钮之前添加尽可能多的条目
,就像
“添加到购物车”
功能一样,在同一页面中显示添加的条目,在一个单独的
div
submit按钮中,然后使用该提交按钮将这些多个条目保存在数据库中(在一个单独的
div
中,显示添加的条目)

到目前为止,我的表单只允许每次提交的条目,这意味着如果用户想要添加其他条目,他/她必须返回表单并添加,然后单击再次提交

<form method="POST" name="myForm" action="saveto.php">
  <label> Speed Rating:</label>
  <select name="speed_rating" required class="form-control" id="speed_rating" ></select>
  <div class="form-group col-sm-8">
    <label> Description:</label>
    <select name="description" required class="form-control" id="description" >
   </select>
  </div>

  <div class="form-group col-sm-4">
  <label> Load Index:</label>
   <select name="load_index" required class="form-control" id="load_index" >
   </select>
  </div>
  <div class="form-group col-sm-6">
  <label> Vendor:</label>
   <select name="vendor" required class="form-control" id="vendor" >
  </select>
  <div class="note"> Recommended Vendor : <span id="recomvend"> </span> </div>
  </div>        
  <div class="form-group col-sm-6">
  <label> Quantity:</label>
  <input type="text" required name="qty" class="form-control" id="qty"></div>       
  <div style="clear:both"> </div>   
   <input type="submit" name="submit" class="btn btn-primary smp" value="Submit"> &nbsp; &nbsp; 
  <button id="clear"  type="button" class="btn btn-primary smp smp2" > Reset </button>
  </div>
  <input type="submit" value="submit" name="submit">
</form>

额定速度:
说明:
负荷指数:
小贩:
推荐供应商:
数量:
重置
你是如何做到这一点的?我的
saveto.php
只是一个普通的脚本,它将处理提交到数据库的数据,每次提交一个条目。

我创建了这个JSFIDLE

如果这是您正在寻找的,那么您应该将其添加到前端:

<form action="validate.php" method="post">
  <div style="padding: 30px 0; text-align: center;">
    <button type="button" onclick="createDOM()">Add</button>
    <input type="submit" value="submit" name="submit" />
  </div>
  <div class="productsContainer"></div>
</form>

<script>
  $(document).ready(function() {
    id = 0;
    createDOM = function() {
      $(".productsContainer").append('<input type="text" id="' + id + '" name="products[]" value="' + id + '" />');
     id++;
    };
  });
</script>
我创建了这个JSFIDLE

如果这是您正在寻找的,那么您应该将其添加到前端:

<form action="validate.php" method="post">
  <div style="padding: 30px 0; text-align: center;">
    <button type="button" onclick="createDOM()">Add</button>
    <input type="submit" value="submit" name="submit" />
  </div>
  <div class="productsContainer"></div>
</form>

<script>
  $(document).ready(function() {
    id = 0;
    createDOM = function() {
      $(".productsContainer").append('<input type="text" id="' + id + '" name="products[]" value="' + id + '" />');
     id++;
    };
  });
</script>

您需要在客户端创建新的表单输入以及创建它们的控件,并更新服务器端代码来处理它们。查看用于命名输入的[]符号。您需要在客户端创建新的表单输入以及创建它们的控件,并更新服务器端代码以处理它们。查看[]符号以命名输入。@Dagon同意。如果他们决定在某个时候使用javascript进行验证,这可能会很有用later@Braza,我编辑了我的问题,我意识到我需要为form@DanielleRoseMabunga你所说的选择标签是什么意思?选择/选项表单元素还是标记选择器?我的意思是选择/选项表单元素在提交之前,我需要在单独的div中显示所有添加字段的值it@Dagon同意。如果他们决定在某个时候使用javascript进行验证,这可能会很有用later@Braza,我编辑了我的问题,我意识到我需要为form@DanielleRoseMabunga你所说的选择标签是什么意思?选择/选项表单元素还是标记选择器?我的意思是选择/选项表单元素在提交之前,我需要在单独的div中显示所有添加字段的值