Skip to main content
Ben Nadel at cf.Objective() 2014 (Bloomington, MN) with: Jojo Serquina
Ben Nadel at cf.Objective() 2014 (Bloomington, MN) with: Jojo Serquina ( @jojoserquina )

FireFox Fires OnClick Handler for Submit Buttons

By on

I just discovered something by accident in my code. It seems FireFox will trigger the onClick event for a submit button even if the FORM element is submitted via the Return Key:

<input type="submit" value="Save" onclick="alert('This will fire in FireFox');" />

I think this is really cool, though not sure if it is a bug or a feature. Internet Explorer (IE) on the other hand, does not perform this action.

Want to use code from this post? Check out the license.

Reader Comments

1 Comments

Hi...

I found your blog when i was searching on how to fix the 'onclick' event not firing in firefox...

And i think you just gave me the solution...haha

1 Comments

post a solution to following problem:
- if I have 3 buttons and 2 of them would have to do submit.
how would you handle it?

<input type="button" name="ask_later" value="Ask Me Later" OnClick="frmPreferences.submit();">
<input type="button" name="btnCancel" value="Cancel" OnClick="history.back()">
<input type="submit" name="btnSavePreferences" value="Save Preferences"></td>

I need on when user would click "ask me later" the cookie would be created. so I assume via submit - I wil lreload a page, and its be in the code to do it.

1 Comments

You too? My friend just thought of that also. He mentioned that we could get a code on that. And you have one. That's awesome. Having Mozilla Firefox is way better than the IE, I swear. For all the add-ons, Firefox has it.

I believe in love. I believe in compassion. I believe in human rights. I believe that we can afford to give more of these gifts to the world around us because it costs us nothing to be decent and kind and understanding. And, I want you to know that when you land on this site, you are accepted for who you are, no matter how you identify, what truths you live, or whatever kind of goofy shit makes you feel alive! Rock on with your bad self!
Ben Nadel