I have a form that created in an external file and then i'm including it by php and then getting this form by its id to serialize. index.php
<div id="addressesList">
<?php include 'addresstable.php' ?>
</div>
view source of index.php file:
jquery code in index.php:
<script>
function editAddress(){
$.ajax({
url: 'insert.php',
type: 'POST',
data: $('#addressListForm').serialize() , // An object with the key 'submit' and value 'true; + '&' + 'editAddress' + '=' + id
success: function (result) {
//$(thisObj).parents("tr:first").remove();
$("#addressesList").html(result);
}
});
}
</script>
I want to get the form that its id is "addressListForm" by click on an element that calls editAdress function. addresstable.php file
<?php
$i=1;
$results=mysqli_query($dbCnn,"select * from addresses");
while( $row=mysqli_fetch_array($results,MYSQLI_ASSOC))
{
echo '<form action="insert.php" method="post" id="addressListForm">';
echo "<tr>
<input type='hidden' value='$row[id]' name='id'/>
<td>$i</td>
<td><input name='title' type='text' value='$row[title]' style='width:60px' /></td>
<td><input name='address' type='text' value='$row[address]' style='width:100%' /></td>
<td><input name='tel' type='text' value='$row[phone]' required='required' style='width:100px' /></td>
<td><input name='fax' type='text' value='$row[fax]' required='required' style='width:100px' /></td>
<td><i onclick=\"editAddress($row[id],this)\" class='fa fa-pencil-square-o' title='ثبت تغییرات رایانامه'></i></td>
<td><i onclick=\"deleteAddress($row[id],this)\" class='fa fa-trash-o deletUser' title='حذف کاربر' ></i></td>
</tr>";
$i++;
echo"</form>";
}
?>
</tbody>