Here is my code
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("form").submit(function(event){
event.preventDefault();
alert("Submit prevented");
});
});
function ShowAlert()
{alert("Form Submitted");}
</script>
</head>
<body>
<form action="">
First name: <input type="text" name="FirstName" value="Al"><br>
Last name: <input type="text" name="LastName" value="McCoy"><br>
<input id="ffff" type="submit" value="Submit" onclick="ShowAlert()">
</form>
</body>
</html>
The expected behaviour is only "Submit prevented" will be alerted, but in real "Form Submitted" and "Submit prevented" are both alerted, in the given order.
But I want only the "Submit prevented" to be alerted. Is there a way to prevent onclick
from being executed?