2012-02-22 95 views
0

我通过javascript制作了一个动态文本框,现在我想将所有动态生成的文本框的数据发布到php脚本中,然后插入表中。我怎么能做到这一点...如何将动态文本框的值传递给另一个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> 

回答

0

你可以使用这个$_POST['intTextBox']文本框的值,并用它来inserttable

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) 
+0

你有要在表单标签中提及action属性,请纠正它 – 2012-02-22 08:36:16

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>