two different behaviours with 'return value' of a function

Giganews Newsgroups
Subject: two different behaviours with 'return value' of a function
Posted by:  Dave (…@dsfg.vb)
Date: Fri, 5 Sep 2003

Hi,

I tried something with 'return value' of a function and i got two different
behaviours.
My question is: why does method 1 not work?
Thanks
Dave

method 1: here, whatever i choose (ok or cancel), i go to 'webpage.htm'
<body>
<a id="my" onClick="retvalue()"  href="webpage.htm"  >click here</a>

<script type="text/javascript">
function retvalue()
{
    if (confirm("go to link?") == false)
    return false
}
</script>
</body>

method 2: here, when clicking on 'cancel', i don't go to 'webpage.htm'
<body>
<a id="my" href="webpage.htm"  >click here</a>

<script type="text/javascript">
function retvalue()
{
    if (confirm("go to link?") == false)
    return false
}
document.getElementById("my").onclick=retvalue
</script>
</body>

Replies