I have checked How to get ID of button user just clicked? this question before asking.
I am trying to get the id of button. Below are the codes.
<form name="edit_posting1" id="edit_posting1" method="post" action="edit_posting_bk.php" role="form">
<center>
<input class="btn btn-home" type="submit" name="publish" id="publish" alt="Publish" value="Preview"/>
<input class="btn btn-home" type="submit" name="save" id="save" onclick="return confirm('Are you sure you want to Submit.')" alt="Save" value="Save"/>
<?php
if($disable == true){
echo '<input class="btn btn-home" type="submit" name="disable" id="disable" alt="Disable" value="Disable"/>';
}else{
echo '<input class="btn btn-home" type="submit" name="enable" id="enable" alt="Enable" value="Enable"/>';
}
?>
</center>
Ajax Code
<script type="text/javascript">
$("#edit_posting1").on("submit", function(e) {
e.preventDefault;
var btn = $('#publish');
//var el = 'publish';
var el = $(btn).attr('id');
alert(el);
})
</script>
As per my understanding issue with Ajax code. Can somebody advise me on this?
Thanks
Note: What i want is if user click on enable/disable or publish button i get the id or name of the button.