I have a function called block which simply return false;
this is meant to stop the form being submitted so the ajax functions can capture its submit, however firefox seems to treat it as an actual url and loads the url javascript:block();
if i have action=”javascript: return false;” then firefox doesnt even let the ajax functions handle it.
how can i fix this?
Javascript code doesn’t belong in the
actionattribute. You can use theonsubmitevent.note however that it’s considered good style to specify an
actionthat will work if the user has JavaScript turned off (graceful degradation). If you don’t specify anactionproperty, the form will be submitted to the current page URL.@Justin correctly notes that having JavaScript code in the HTML markup is strictly speaking always a bit dirty. The good practice would be giving the form an
idattribute, and assigning the JavaScript code to that element in theheadpart.With pure Javascript:
With jQuery