I have php form in while loop with different id.
<?php
while($pet = $results->fetch(PDO::FETCH_ASSOC)){
         ?>
<form method="post" name="petForm" id="petForm">
            <ul id="listAvatars">
                <li>
                <input type='text' name='pet' id='pet' value='<?=$pet['PetId']?>' />
                <img src="<?=PET_AVATAR.$pet['Avatar']?>" class="listAvatar">
                <span onclick='setPet(<?=$pet['PetId']?>)' id="avatarName"><?=$pet['PetName']?></span>
                </li>
            </ul>
</form>
           <?php
    }
?>
I want to get different pet id on click event. I am getting valid pet id on click name, by this function.
function setPet(petId){
    alert(petId);
    document.getElementById("petForm").submit();
}
PHP:
if(isset($_POST['pet'])){
    $petId = $_POST['pet'];
    print_r($petId);
}
By submitting this form, I am getting only the first pet's id. What should I do to get appropriate pet id on select?