Ben Nadel
On User Experience (UX) Design, JavaScript, ColdFusion, Node.js, Life, and Love.
Ben Nadel at cf.Objective() 2014 (Bloomington, MN) with: Joel Hill and Matt Vickers and Shawn Grigson and Jonathan Rowny and Jonathan Dowdle and Christian Ready and Oscar Arevalo and Jeff McDowell and Steve 'Cutter' Blades
Ben Nadel at cf.Objective() 2014 (Bloomington, MN) with: Joel Hill@Jiggidyuo ) , Matt Vickers@envex ) , Shawn Grigson@shawngrig ) , Jonathan Rowny@jrowny ) , Jonathan Dowdle@jdowdle ) , Christian Ready@christianready ) , Oscar Arevalo@oarevalo ) , Jeff McDowell@jeff_s_mcdowell ) , and Steve 'Cutter' Blades@cutterbl )

FireFox Fires OnClick Handler for Submit Buttons

By Ben Nadel 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.


Looking For A New Job?

100% of job board revenue is donated to Kiva. Loans that change livesFind out more »

Reader 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

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.

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.