/    Sign up×
Community /Pin to ProfileBookmark

When to use ‘return’

In the past I have used code that looks something like this …
<form action=”url…” onsubmit=”jsfunction()”>
where the function would ‘return false’ if it fails, and would return nothing if valid.

On this board I noted that the correct method should be as follows..
<form action=”url…” onsubmit=”return jsfunction()”>
and the function should return true or false.

Secondly, I’ve seen, and used, snippets of code like this, sometimes with and sometimes without the return.
… onmouseover=”jsfunction(); return true”..

Thirdly, event handlers sometimes return true or false, but not always.

I’ve read though the javascript documentation and one of the O’Reilly books on javascript and I notice that, again, the ‘return’
is sometimes included and somtimes not.

Could someone explain WHEN, and more importantly WHY, a return should be used? Is there a good source to read up on this?

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @Nedals spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...