I have a link. Whenever it is clicked, a new page will be displayed which contains data such as id
, name
, price
and a select option with a check box. This page also contains a button. All these details (id
, name
, price
) are fetched from a table. If the check box is checked and the button is clicked, a new page with the selected values along with a text box for each id should be displayed. If a value is entered in those text boxes and the button is clicked, I should fetch the value of the text box. I have given the text box the name id
(which is retrieved from the table).
Well, there are two ways of doing this.
Name your text boxes as an array. So the name would be name[]
or name[2]
. Then, in PHP just loop over $_POST['name']
which will be an array (or empty if no text boxes were added). That way, you only need to submit the data that exists...
The other way would be to use Javascript to do the submission. You'd need to assemble the response into a common format (JSON perhaps) and then send that to the server...
But it's definitely possible...
I assume the new text box is created using javascript. Give it a fixed name
attribute that your PHP script knows and read it from _POST[]
You can use a naming convention for the name property of the textboxes that append an integer value to the end of the whatever generic name you use. Store the number of textboxes created and once the page is posted, you can reconstruct the name of the textboxes with a loop and read the posted values.