0

i make a dynamic textbox through javascript now i want to post the data of all dynamically generated textboxes to php script and then insert into a table. how can i do this...

> 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>
Gagan
  • 31
  • 1
  • 5

4 Answers4

0

you can get value of this textbox using $_POST['intTextBox'] , and use it to insert into table

linuxeasy
  • 6,269
  • 7
  • 33
  • 40
pkachhia
  • 1,876
  • 1
  • 19
  • 30
0

Just use POST Method ,you will get all the filled values in another page

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

 -----destination.php---

    print_r($_POST)
Duke
  • 35,420
  • 13
  • 53
  • 70
0

You can use $_POST arrays. By using the same name with brackets. You can check this post : Submitting a multidimensional array via POST with php

Community
  • 1
  • 1
iceduck
  • 163
  • 9
0

Do this in your javascript for any textbox you wanna add dynamically

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

then after submision in your add_save.php do this

 $boxValue=$_REQUEST['box1'];

 <tr><?=$boxValue ?></tr>
jmishra
  • 2,086
  • 2
  • 24
  • 38