943,945 Members | Top Members by Rank

Ad:
Oct 22nd, 2009
0

What's the difference..?

Expand Post »
Hi can someone please explain to me what is the difference between writing

onclick="confirmLink()"

and

onclick="return confirmLink()"

I tried both and they did the same thing and I am confused since the lazy fellows from my university have given me old notes in which they randomly include the "return" sometimes and sometimes they don't in the various examples.


JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <title>Handling onClick for links</title>
  4. <script>
  5. <!--
  6. function confirmLink()
  7. {
  8. alert("This is the Mastering JavaScript and JScript Home Page.");
  9. return confirm("Are you sure you want to load this document?")
  10. }
  11. //-->
  12. </script>
  13. </head>
  14. <body>
  15. <h1>Handling onclick for links</h1>
  16. <p>
  17. <a href="http://www.jaworks.com/javascript" onclick="confirmLink()">Asks you
  18. to confirm your selection of this link.</a>
  19. </p>
  20. </body>
  21. </html>
Last edited by DARK_BYTE; Oct 22nd, 2009 at 4:30 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
DARK_BYTE is offline Offline
50 posts
since Sep 2009
Oct 22nd, 2009
0
Re: What's the difference..?
NO, both will behave differently if you click 'cancel' on confirmation dialog instead of clicking 'ok'.

Now its ur job to figure out something from this.
Reputation Points: 83
Solved Threads: 61
Posting Pro in Training
Luckychap is offline Offline
442 posts
since Aug 2006
Oct 22nd, 2009
0
Re: What's the difference..?
Try this example:

html Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <title>Handling onClick for links</title>
  4. <script>
  5. <!--
  6.   function confirmLink()
  7.   {
  8.   alert("This is the Mastering JavaScript and JScript Home Page.");
  9.   return confirm("Are you sure you want to load this document?")
  10.   }
  11.   //-->
  12. </script>
  13. </head>
  14. <body>
  15. <h1>Handling onclick for links</h1>
  16. <p>
  17. <a href="http://www.jaworks.com/javascript" onclick="">without retrun.</a><br>
  18. <a href="http://www.jaworks.com/javascript" onclick="return">with only retrun.</a><br>
  19. <a href="http://www.jaworks.com/javascript" onclick="return true;">with retrun true.</a><br>
  20. <a href="http://www.jaworks.com/javascript" onclick="return false">And with retrun false.</a><br>
  21. </p>
  22. </body>
  23. </html>

Run this u will get all ur answers.
Reputation Points: 83
Solved Threads: 61
Posting Pro in Training
Luckychap is offline Offline
442 posts
since Aug 2006
Oct 22nd, 2009
0
Re: What's the difference..?
What I understand from this is that I can stop the default action from occuring if it return false!Thx.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
DARK_BYTE is offline Offline
50 posts
since Sep 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Table id
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: mailto error handling





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC