Have you tried this:
<td>
<a id="id1" class="class1" href="#" title="title1" onclick="foo(event,
'myval');return false;">Some text</a>
</td>
Adding "return false" to the onclick event should prevent the browser
from trying to follow the default event.

On Jan 8, 9:36 am, Mahoney <[email protected]> wrote:
> Hi,
>
> Using Prototype 1.5 in Firefox 3.
>
> I'm seeing some very odd behaviour with some anchor tags, which insist
> on following the anchor despite me returning false from a method
> called onclick and stopping the event in that method.
>
> Here's the code:
> function foo(event, someVal) {
>   Event.stop(event);
>   // Do some stuff with someVal
>   return false;
>
> }
>
> <td>
> <a id="id1" class="class1" href="#" title="title1" onclick="return foo
> (event, 'myval');">Some text</a>
> </td>
>
> The JavaScript is definitely not causing an exception (no errors in
> firebug console, the method successfully does what it's meant to).
>
> Some particularly odd features:
> 1) It works as I want it to if I use firebug to put a break point in
> foo - the page stays where it is instead of jumping to the top
> (following the anchor).
> 2) It works as I want it to if I save the HTML page locally and test
> the local copy
> 3) If I wrap the text in a span, as so:
> <td>
> <a href="#" onclick="return foo(event, someVal);"><span>Some text</
> span></a>
> </td>
> it works as I want it to if, and only if, I click on the text itself -
> if I click elsewhere in the TD it fires the anchor's onclick event and
> also follows the anchor so the page resets to the top.
>
> I tried putting an alert at line 1 of foo() - the page jumps to the
> top before I click "OK".  So it's as if the event's default action
> occurs before the method added as a handler can stop it!
>
> This has me baffled - there must be something in the page as rendered
> that's screwing up the event handling, but I've even gone down the
> lengths of deleting most of the page in firebug hoping to work out
> what was causing it.  Does anyone have any ideas of where I should
> concentrate?
>
> Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to