Consider the following examples of Javascript attributes in HTML elements:
<input type="button" onclick="somceFunc()" />
<input type="button" onclick="somceFunc();" />
<input type="button" onclick="somceFunc(); return false;" />
When should one end the someFunc() call with a semi-colon, and when should the semi-colon be eliminated? Also, when should one end the attribute with a call to return false;?
Thanks.
That’s a semi-colon. Always end expressions with one. Automatic semi-colon insertion has enough gotchas that you are better off just avoiding it.
falseis a literal, not a function, you can’t call it.The usage in that example does absolutely nothing.
If you were to
return falsefrom an intrinsic event attribute (likeonclick) then you would stop the default action of the control from firing. e.g. a link would not be followed. A button has no default action though.Intrinsic event attributes should be avoided in favour of unobtrusive JavaScript.