如何将动态文本框值传递给另一个php页面

时间:2012-02-22 08:28:09

标签: php javascript

我通过javascript创建一个动态文本框现在我想将所有动态生成的文本框的数据发布到php脚本然后插入到表中。我怎么能这样做......

> var intTextBox=0;
> 
> //FUNCTION TO ADD TEXT BOX ELEMENT 
> function addElement() { 
> intTextBox = intTextBox+1;
> 
> var contentID = document.getElementById('content'); 
> var newTBDiv =document.createElement('div');
> newTBDiv.setAttribute('id','strText'+intTextBox); 
> newTBDiv.innerHTML="Author  : <input type='text' id='citingfield' name='"intTextBox"'/>";
> contentID.appendChild(newTBDiv);
> }
> 
> //FUNCTION TO REMOVE TEXT BOX ELEMENT 
> function removeElement() {
> if(intTextBox != 0) 
> {
> var contentID = document.getElementById('content');
> contentID.removeChild(document.getElementById('strText'+intTextBox));
> intTextBox = intTextBox-1; } }
> 
> <body>
> 
> <form action="add_save.php" method="post"  > 
> 
> <div id="content"></div> <p><a href="javascript:addElement();"
> >Add</a> <a href="javascript:removeElement();" >Remove</a></p>
> 
> <input name="submit" type="submit" id=" " value="Submit">
> </from>

4 个答案:

答案 0 :(得分:0)

您可以使用$_POST['intTextBox']获取此文本框的值,并将其用于insert进入table

答案 1 :(得分:0)

只需使用POST方法,您将获得另一页中的所有填充值

--- index.php---    
    <form method="POST" action="destination.php">
    your code here. Dynamically created code will append to here
    </form>

 -----destination.php---

    print_r($_POST)

答案 2 :(得分:0)

您可以使用$ _POST数组。 通过使用带括号的相同名称。 你可以查看这篇文章: Submitting a multidimensional array via POST with php

答案 3 :(得分:0)

在您的javascript中为您想要动态添加的任何文本框执行此操作

      var box=document.createElement("input");
      box.setAttribute("type","text");
      box.setAttribute("name","box1");
      box.setAttribute("value","someNewValue");
      content.appendChild(box);

然后在你的add_save.php中进行submision后执行此操作

 $boxValue=$_REQUEST['box1'];

 <tr><?=$boxValue ?></tr>