0

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.

<html>
  <head>
    <title>Handling onClick for links</title>
    <script>
      <!--
      function confirmLink()
      {
      alert("This is the Mastering JavaScript and JScript Home Page.");
      return confirm("Are you sure you want to load this document?")
      } 
      //-->
    </script>
  </head>
  <body>
  <h1>Handling onclick for links</h1>
  <p>
    <a href="http://www.jaworks.com/javascript" onclick="confirmLink()">Asks you
       to confirm your selection of this link.</a>
  </p>
  </body>
</html>

Edited by DARK_BYTE: n/a

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by DARK_BYTE
0

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.

0

Try this example:

<html>
  <head>
    <title>Handling onClick for links</title>
    <script>
      <!--
      function confirmLink()
      {
      alert("This is the Mastering JavaScript and JScript Home Page.");
      return confirm("Are you sure you want to load this document?")
      } 
      //-->
    </script>
  </head>
  <body>
  <h1>Handling onclick for links</h1>
  <p>
    <a href="http://www.jaworks.com/javascript" onclick="">without retrun.</a><br>
    <a href="http://www.jaworks.com/javascript" onclick="return">with only retrun.</a><br>
    <a href="http://www.jaworks.com/javascript" onclick="return true;">with retrun true.</a><br>
    <a href="http://www.jaworks.com/javascript" onclick="return false">And with retrun false.</a><br>
  </p>
  </body>
</html>

Run this u will get all ur answers.

0

What I understand from this is that I can stop the default action from occuring if it return false!Thx.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.