Return value from event handlers necessary?

W

Water Cooler v2

Is it necessary to return a value from the event handlers? For
instance, what does the return value in the following code signify?
What will be its impact if it returned otherwise (true)?

<a href="http://www.w3schools.com"
onmouseover="alert('An onMouseOver event'); return true">
<img src="Click.gif" width="100" height="30">
</a>
 
R

Randy Webb

Water Cooler v2 said the following on 4/18/2006 10:25 AM:
Is it necessary to return a value from the event handlers?

No. But it depends on what you are trying to do with the event handler
and what the elements default behavior is. Not returning true or false
from an onsubmit handler defeats the purpose of using it. But returning
true/false from the onclick of a Button element wouldn't serve any purpose.
For instance, what does the return value in the following code signify?
What will be its impact if it returned otherwise (true)?

Put two links on a page, one with return true and one with return false.
Then mouse over them and see what is different.
<a href="http://www.w3schools.com"
onmouseover="alert('An onMouseOver event'); return true">
<img src="Click.gif" width="100" height="30">
</a>

<a href="http://www.w3schools.com"
onmouseover="alert('An onMouseOver event'); return true">
<img src="Click.gif" width="100" height="30">
</a>
<a href="http://www.w3schools.com"
onmouseover="alert('An onMouseOver event'); return false">
<img src="Click.gif" width="100" height="30">
</a>

And then mouseover them and observe the browser. Nothing better than
testing code to see what it does :)
 
W

Water Cooler v2

Thanks for your reply, Randy.

I'd done that before I posted this question. I didn't observe any
difference and my question was perhaps leaning towards, "what are the
events where the return value is significant?"
 
R

Randy Webb

Water Cooler v2 said the following on 4/18/2006 11:26 AM:
Thanks for your reply, Randy.

Thanks for quoting next time :)
I'd done that before I posted this question. I didn't observe any
difference and my question was perhaps leaning towards, "what are the
events where the return value is significant?"

onclick of a link -
return true allows navigation after the code is executed.
return false cancels navigation after the code is executed.

onsubmit of a form
return true allows submission of the form.
return false cancels submission of the form.

That is two quick one's off the top of my head.

General Rule:
return true - allows default action of the element.
return false - cancels default action of the element.
 
W

Water Cooler v2

return true allows navigation after the code is executed.
return false cancels navigation after the code is executed.

Just another tiny bit: what do you mean by "navigation" here?
 
M

Michael Winter

Thanks a big bunch, Randy. How do I rate this topic?

Please realise that you are posting to Usenet. Google Groups is just an
interface to it, and a substandard one at that.

You've been pointed to information about using Google Groups properly in
previous threads. The group FAQ also has detailed information about
posting to this group. Please read them, both. Whether you realise it or
not, it does benefit both you and the rest of us.

Mike
 
W

Water Cooler v2

Thanks, Mike. I'll try and look up the FAQ. Could you please suggest a
good newsreader. I use both IE 6 and Firefox 1.5. I also have RSSBandit
and Awasu for RSS feeds, but I am not sure if they read newsgroups and
I'll be able to rate posts with them.
 
M

Michael Winter

I'll try and look up the FAQ.

Parts of it are posted to this group every Monday, Wednesday, and
Friday, and include links to the full document:
Could you please suggest a good newsreader.

In no particular order: Thunderbird, Mozilla, Forte, Gravity, XNews, and
KNode. They're all newsreaders that I've used at one time or another.
There are plenty of others (for all platforms).
I use both IE 6 and Firefox 1.5.

A browser is not necessary to use Usenet.

Does your ISP provide a news (NNTP) server? That's a more important
question.
[...] I am not sure if they read newsgroups and I'll be able to
rate posts with them.
^^^^^^^^^^
There is no concept of post ratings in Usenet (nor is there much value
in such a feature).

Mike
 
R

Randy Webb

Water Cooler v2 said the following on 4/18/2006 12:11 PM:

Group FAQ: http://jibbering.com/faq

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.
Just another tiny bit: what do you mean by "navigation" here?

Changing the page you are viewing - at it's simplest.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top