with inline event listeners I mean HTML elements attributes for event registration like onsubmit/onreset attributes rather than dom node properties for registering event.
I’m asking because when I register an event handler that returns false to onsubmit/onreset attributes of a form, by submitting/reseting the submit/reset process is performed.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Web Project</title>
<script type="text/javascript">
function f()
{
return false;
}
</script>
</head>
<body>
<form action="" id = "form" onsubmit = "f()" onreset = "f()">
<input type="text">
<input type = "submit" value = "submit">
<input type = "reset" value = "reset">
</form>
</body>
</html>
When you provide event handlers via the HTML attributes, the string you provide creates a function which is called by the browser when the event occurs.
So in your example, the onsubmit and onreset attributes create two functions equivalent to:
Because that anonymous function doesn’t return false, the submit and reset events aren’t blocked. If that is what you want to do, you can do one of the following.
To always block default handling:
To conditionally block default handling (and a little bit better code style, IMO):