Jump to content

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


Go to solution Solved by jugesh,

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.

http://jsfiddle.net/NSePb/1/

 

 

 

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

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....

 

}

}

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. 

  • Solution

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.