javascript click event/submit not working in Firefox

I have an aspx page with two different buttons in the same form.  Depending on what field the user is typing in, I want the enter key to submit using one button or the other.

asp button code: <asp:LinkButton ID="btnLogin" CssClass="button signIn" Text="Sign In" onClick="btnLogin_Click" runat="server" ValidationGroup="Login">

Using the following javascript function, I'm trying to get a button click event to fire.  The function seems to work in IE, Safari, etc., but not Firefox.
buttonLogin: function(e) {
   if(window.event) // IE
   {
      characterCode = e.keyCode;
   }
   else if(e.which) // Netscape/Firefox/Opera
   {
      characterCode = e.which;
   }
   
   if(characterCode == 13) {
      try {
         var evt = document.createEvent("MouseEvents");
         evt.initMouseEvent("click", true, true, window,
            0, 0, 0, 0, 0, false, false, false, false, 0, null);
         var btn = $('btnLogin');
         btn.dispatchEvent(evt);
      }
      catch(er) {
         $('btnLogin').click();
      }
      return false;
   }
   else {
      return true;
   }
}

Open in new window

chipotleitAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wassa_rCommented:
Try this instead:

characterCode  = (window.event) ? event.keyCode : e.keyCode;
0
chipotleitAuthor Commented:
I'll need to add some clarification.  In Firefox, it gets the keypress and will get into the "if(characterCode == 13)" statement, but won't actually fire the click event on either route.
0
wassa_rCommented:
What library are you using ( regarding the $ ), in a good library $('bla').click(); should just work.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

chipotleitAuthor Commented:
The site is using mootoolsCore 1.2

If I just use the $('btnLogin').click(); it won't do anything in Firefox.

Firefox currently goes into the try block of code, but the code doesn't produce any actions or errors, so won't go into the catch block either.
0
chipotleitAuthor Commented:
The Answer:

the asp LinkButton is rendered in html as an anchor "a" tag, which doesn't seem to support a click event in Firefox.  I changed the LinkButton to an image button, so it is rendered as an "input" and works fine now.
0
chipotleitAuthor Commented:
your comments got me thinking about this a little more, and started digging again.  I figured it had to be something small like this.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Browsers

From novice to tech pro — start learning today.