...

View Full Version : newbie. Don't understand return false from a function



Roy Gardiner
01-08-2004, 03:53 PM
My first ever question; pls let me know if it's formulated in a suitable style. This Script:

<SCRIPT LANGUAGE="JavaScript">
<!-- Hide code from older browsers
function heading() {
return false;
}
// End hiding-->
</SCRIPT>

Is referenced:

<A HREF="./politics.htm" onClick="heading()">my politics</a>
<A HREF="./politics.htm" onClick="heading(); return false">my politics 2</a>
<A HREF="./politics.htm" onClick="return true">my politics 3</a>

In case 1 I expected the link not to be taken, but it is.
Case 2 link not taken, as expected
Case 3 link taken, as expected.

In what respect is my expectation wrong for case 1?

Roy Sinclair
01-08-2004, 04:26 PM
The calls are incorrect:



<A HREF="./politics.htm" onClick=" return heading()">my politics</a>
<A HREF="./politics.htm" onClick="heading(); return false">my politics 2</a>
<A HREF="./politics.htm" onClick="return true">my politics 3</a>


You need to "return" the value from the function, just calling the function inline without the return verb causes the value returned by the function to be ignored.

Roy Gardiner
01-08-2004, 06:43 PM
Originally posted by Roy Sinclair
You need to "return" the value from the function, :) Thank you, Roy. What a :o, sorry.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum