Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Return value from event handlers necessary?

Reply
Thread Tools

Return value from event handlers necessary?

 
 
Water Cooler v2
Guest
Posts: n/a
 
      04-18-2006
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>

 
Reply With Quote
 
 
 
 
Randy Webb
Guest
Posts: n/a
 
      04-18-2006
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

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
 
Reply With Quote
 
 
 
 
Water Cooler v2
Guest
Posts: n/a
 
      04-18-2006
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?"

 
Reply With Quote
 
Randy Webb
Guest
Posts: n/a
 
      04-18-2006
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.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
 
Reply With Quote
 
Water Cooler v2
Guest
Posts: n/a
 
      04-18-2006
Thanks a big bunch, Randy. How do I rate this topic?

 
Reply With Quote
 
Water Cooler v2
Guest
Posts: n/a
 
      04-18-2006
> 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?

 
Reply With Quote
 
Michael Winter
Guest
Posts: n/a
 
      04-18-2006
On 18/04/2006 17:07, Water Cooler v2 wrote:

> 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

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
 
Reply With Quote
 
Water Cooler v2
Guest
Posts: n/a
 
      04-18-2006
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.

 
Reply With Quote
 
Michael Winter
Guest
Posts: n/a
 
      04-18-2006
On 18/04/2006 20:37, Water Cooler v2 wrote:

> 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:
<http://www.jibbering.com/faq/>

> 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

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
 
Reply With Quote
 
Randy Webb
Guest
Posts: n/a
 
      04-19-2006
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.
<URL: http://www.safalra.com/special/googlegroupsreply/ >

>> 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?


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


--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
atexit handlers - getting the return code Mike Hull Python 4 09-27-2011 07:12 PM
what value does lack of return or empty "return;" return Greenhorn C Programming 15 03-06-2005 08:19 PM
About Event Handlers, Delegates and Scopes Alex MCSD 6 05-21-2004 01:49 AM
Re: crazy event handlers! Trevor Hartman ASP .Net 2 06-26-2003 01:53 AM
Dynamic Buttons and Event Handlers, revisited Boban Dragojlovic ASP .Net 0 06-24-2003 01:51 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57