I have a dynamic loop pulling data from a sql table. How can I get the value of the specific mile_id
saved into a js variable when the delete button is pressed? It is noted that there will be multiple forms due to the form being inside the loop.
FORMs
while($row = mysqli_fetch_array($result)){
echo '
<form>
<input type="hidden" id="mile_id" value="'.$row['mile_id'].'" />
<input type="button" id="delete" value="DELETE'.$i.'" />
</form>';
}
JS
$(document).ready(function(){
$('form #delete').click(function(e){
var $mile_id = $('#mile_id') // this returns [object Object]
var yes = confirm("Are you sure?");
if (yes){
alert($mile_id);
}
else{
return false;
}
});
});