Jump to content

How to post the dynamically created text box values to next page in php and insert those values into db?


Recommended Posts

I am a newbee in php, jquery and ajax. I have a code in jquery to add and remove the textboxes dynamically on button click. I want to post the values of dynamically created textbox values to next page and display those values on action page as well as insert them into db. Any help is much appreciated. Thanks in advance.


Please click on the link to see how the textboxes are dynamically created.





I have uploaded the two pages.

I want to post the data from quotations.phpquotations.php to quot_rec.php and display the posted values on quot_rec.phpquot_rec.php

Link to comment
Share on other sites

populate the text fields name as array like  <input type='textbox' id='Location1' name="Location[]">


now while saving the data follow like this:

 if ($_POST['Location']) {

        //get last inserted userid
         foreach ($_POST['Location'] as $key=>$value) {


/// Do your coding....




Link to comment
Share on other sites

Thanks jugesh for the response. I hope you seen the jsfiddle link and the pages I have uploaded. In the code the textboxnames are generated dynamically, I mean each time the user clicks the 'Add products' button the counter value gets incremented and the id and the name gets updated with that value for example when the user clicks the 'Add Products' button the textbox names are generated automatically as name="product" + counter, name="qty" + counter, name = "rates" + counter.   


So I want to gather all the dynamically generated textbox values to pass to quot_rec.php and display those values.


I am facing difficulty in storing the dynamically generated textbox values to php variabples. I am working on this for nearly two days. 

Link to comment
Share on other sites

Change your input fields name as an array:


     newTextBoxDiv.after().html('<label>Product #'+ counter + ' : </label>' +
          '<input type="text" size="22" name="product[] " id="product' + counter + '" value="" >      \n\
              <label>Quantity #'+ counter + ' : </label>' +
          '<input type="text" size="1" name="qty[] " id="qty' + counter + '" value="" >      \n\
              <label>Rate #'+ counter + ' : </label>' +
          '<input type="text" size="2" name="rates[] " id="rates' + counter + '" value="" >      \n\
              <label>Total #'+ counter + ' : </label>' +
          '<input type="text" size="3" name="total[] " id="total' + counter + '" value="" > ');




Now post the values  as i did in example it will surely work

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.