Dynamically add pre-filled forms from database using ajax and jquery

I have been researching online for a couple of days and I cannot find an answer to my question. I would like to add a div or insert a pre-filled form from my database depending on the dropdown (select from row in my DB). Once you click on the button, it will add the form field to the div or area above. Any suggestions? How do I solve this? I'm extremely new to JQuery and Ajax but know PHP well.

+3


source to share


1 answer


One way is to fill in the fields when the page loads. (pass values ​​to the html page with"value=<$php echo $someData %>"

if you want to load data without refreshing the page every time, I suggest you create another page that will load data from the database via POST requests and retrieve the data as JSON so that you can parse it with Javascript and update the fields accordingly.

Updating fields can be done as follows:



json = YourJSONData;    
$('.some-class').val(json['someData']); // if populating a form field
$('.some-other-class').html(json['someOtherData'); // if populating a div or other DOM element.

      

etc...

+1


source







All Articles