views:

255

answers:

2

The following works fine in Firefox and Chrome, but IE 8 will not call the submit() method when the anchor link is clicked.

<a href="javascript:void(0);" onclick="submit();">Sign In</a>

The submit method is defined on the same page as follows:

<head>
<script type="text/javascript">

function submit()
{
// other code                                              
document.forms[0].submit();
}  

</script>
</head>
A: 

Can you provide a bit more context? Such as where and how the submit function is defined? With just the above, it should work -- except:

You probably also want to return false; in there though, to cancel the default action. E.g.:

<a href="javascript:void(0);" onclick="submit();return false;">Sign In</a>

It may be that the default action is happening immediately after the submit and interfering with it.

Edit: Just for fits and giggles, try using a different name for your submit function. IE has namespacing issues. If you have anything with the id or name attribute set to "submit", for instance, that could be an issue...

T.J. Crowder
I tried adding "return false;" with no effect. The IE debugger shows the call to the onclick code, but won't enter the submit() method.
Mark
@Mark: I'm not sure I know what you mean by the debugger showing it entering the `onclick` code but not entering the `submit` method. Is there an exception thrown? If not, what happens such that it "won't" enter the function?
T.J. Crowder
Thanks for responding T.J. It's odd really. I set the IE 8 debugger to "break on all". As soon as I click the "Sign In" link, the debugger breaks and highlights onclick="submit();" in the anchor. I assume the highlighting is to indicate the next instruction to be executed. To be safe, I also set a breakpoint inside the submit method. From this point I click "Step Into" or "Step Over" on the debugger menu. Both have the same effect of highlighting the void(0) method. For some reason IE will not execute the submit() function. I don't see any indication of an error.
Mark
You were right T.J. It was a name space conflict. IE uses submit for something. Once I changed the function name it worked. Thanks again for the help.
Mark
@Mark: Excellent! Glad that helped, I should have thought of it to start with.
T.J. Crowder
A: 

Try using

<a onclick="submit();">Sign In</a>

or

<a href="javascript:submit();">Sign In</a>
irishbuzz