In my coding script, I have a mechanism that dynamically creates form elements along with their unique IDs. For example,
If the response from the MySQL database is 4, then
<form ID="form0">
<Input>....
<Button type="submit>....
</form>
<form ID="form1">
<Input>....
<Button type="submit>....
</form>
<form ID="form2">
<Input>....
<Button type="submit>....
</form>
<form ID="form3">
<Input>....
<Button type="submit>....
</form>
After generating this list of forms, I use AJAX code to identify the submit buttons and send the input values to the database via a PHP page, like demonstrated below:
$(document.body).on('submit', '#form' ,function(e){
e.preventDefault();
var postData = $("#form").serialize();
$.post("../../../functions/processing.php",postData,function(data, status){
var selectedData = JSON.parse(data);
$.each( selectedData, function( i, val ) {
// perform specific tasks here...
});
});
});
My quandary is how to create multiple instances of this AJAX code for each dynamically generated form (form0, form1, form2, form3, etc.), since the number of forms generated is unpredictable. Is there a method to dynamically generate AJAX codes for dynamically created multiple forms?