What's the difference..?

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved

Join Date: Sep 2009
Posts: 16
Reputation: DARK_BYTE is an unknown quantity at this point 
Solved Threads: 0
DARK_BYTE DARK_BYTE is offline Offline
Newbie Poster

What's the difference..?

 
0
  #1
Oct 22nd, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 319
Reputation: Luckychap is on a distinguished road 
Solved Threads: 42
Luckychap's Avatar
Luckychap Luckychap is offline Offline
Posting Whiz
 
0
  #2
Oct 22nd, 2009
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.
When you think you have done a lot, then be ready for YOUR downfall.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 319
Reputation: Luckychap is on a distinguished road 
Solved Threads: 42
Luckychap's Avatar
Luckychap Luckychap is offline Offline
Posting Whiz
 
0
  #3
Oct 22nd, 2009
Try this example:

  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.
When you think you have done a lot, then be ready for YOUR downfall.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 16
Reputation: DARK_BYTE is an unknown quantity at this point 
Solved Threads: 0
DARK_BYTE DARK_BYTE is offline Offline
Newbie Poster
 
0
  #4
Oct 22nd, 2009
What I understand from this is that I can stop the default action from occuring if it return false!Thx.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC