0

I have the following line :

html += '<td><select value="<?php echo $location; ?>" class="form-control" name="data[InvoiceDetail]['+i+'][location]" id="location_'+i+'" placeholder="Location"></td>';

That is a part of a function that adds multiple dynamically added table data and rows. I have other entries that do not mess up the script, such as :

html += '<input type="hidden" id="stock_'+i+'"/>';

I think the problem of the script not working is the ";" after $location, but I do not know how to alter the script to allow this?

So, boiling everything down, how do I add the above line to the dynamically added rows, while retaining the values?

Thanks!

Steven
  • 687
  • 1
  • 10
  • 27

1 Answers1

2

It looks like you are dynamically adding PHP content to your page in the client (browser), but PHP needs to be executed on the server.

Perhaps you could use ajax to request the value of "location" from the server, and then dynamically add it.

This may provide a nice example: using jquery $.ajax to call a PHP function

Community
  • 1
  • 1
Jonathan.Brink
  • 23,757
  • 20
  • 73
  • 115