FireFox Fires OnClick Handler for Submit Buttons

Posted May 15, 2006 at 12:22 PM

Tags: Javascript / DHTML

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:

 Launch code in new window » Download code as text file »

  • <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.

Download Code Snippet ZIP File

Comments (2)  |  Post Comment  |  Ask Ben  |  Permalink  |  Other Searches  |  Print Page




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

Posted by yayai on Dec 1, 2006 at 3:17 AM


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.

Posted by v_max on Apr 8, 2008 at 5:28 PM


Post Comment  |  Ask Ben


Home   |   Web Log   |   ColdFusion   |   Projects   |   Resume   |   Job Form   |   Search   |   Contact
Epicenter Consulting - Custom Software Solutions for Business Evolution HostMySite.com - The Leader In ColdFusion Hosting