How can i perform ajax request for a looped form which has a id of dynamic php variable?

How can i perform ajax request for a looped form which has a id of dynamic php variable?
0

#1

I use php to set id of a loop form to give them seperate id each time the loop execute.

<div id="<?php echo $id ?>"> A form </div>
//$id is the id of a table from database

Every time the loop ececute it automatically has a incremented id.
but as i stored the id in a varibale($id), ajax don’t work.
Ajax can’t recognise which form I had select to work with it as all the looped form has same id($id).

How can i perform ajax request for a looped form which has a id of dynamic php variable? What should I do to make sure ajax understand which form I am filling out and then grabbed that form id to execute php scripts?


#2

Generate the ID when the form gets submitted. If you can’t do that, why not? Need context as to what you’re trying to achieve.

Else you could make a get request to get an id from somewhere PHP side. Now you have the ID, so make a post request with the ID and the form.