Click to See Complete Forum and Search --> : Returning false in an event handler so a link is NOT followed
karayan
07-26-2003, 03:03 PM
While replying to an earlier posting, Pyro mentioned that:
</a href='blabla.com' onClick='some_function(); return false;'>
will cause the browser to run some_function() on click, but NOT follow the link, due to "return false" statement. Would that be also true if I do:
</a href='blabla.com' onClick='some_function()'>
and make sure that the function itself returns false? It doesn't seem to work this way for some reason.
Charles
07-26-2003, 03:07 PM
Use:
<a href="http://www.blah.com/" onclick="return someFunction()">
And note that the handler's name is "onclick" and not "onClick" and that JavaScript follows the Java naming conventions (http://java.sun.com/docs/codeconv/html/CodeConventions.doc8.html).
karayan
07-26-2003, 03:16 PM
Spelling noted!
The problem is that HTML is not case sensitive, and I have gotten used to spelling events that way to make them easier to read. (My Javascript book does this also!!!!) Of course, when I did event handling in Javascript (as in these postings), I hit a brick wall. :D
Where would I be without this forum?
Neiro
07-26-2003, 06:31 PM
Would it be possible to cancel out urls in applets with this? ie put th a href="" onclick etc. around the applet loading?
I ask cause I use a counter that wants to advertise when a user hovers the mouse over it and goes to it's site when clicked on - even if my href tells it to do something else.
Khalid Ali
07-26-2003, 11:50 PM
The method posted above
onclick="return someFunction();"
expects that the function will return a true or false value,if its false then the click event will not execute the href attributes value...
In the applets it could be totally differently implemented,for this you will need to get an API docs from the applet writer to see which method returns what...