views:

207

answers:

4

Hi,

I'm debugging a weird problem with two simlar search forms - when user types some search criteria in a text box and hits enter, one form returns results and another just reloads. And it happens only in IE - FF treats both forms as expected. I suspect that hitting enter is triggering onclick for one of the search buttons in one case and something else in another.

How do I find what form element caused submit event?

Thanks, Andrey

A: 

You could sprinkle your form elements with onclick events to set a hidden form variable with a different value per element, then sniff the results either with a DOM inspector or through something like Fiddler.

There may be a way to simply have a form onsubmit() event that you can extract the triggering element from the event object, but I'd have to dive into the docs to see if this is possible... if I get chance I'll do some looking.

Chris J
It isn't directly possible to tell which button was pressed from onsubmit (until the name/value pair for it hits the server). There are unhappy workarounds with detecting buttons clicks and enter presses, but it's not much fun.
bobince
+1  A: 

Sounds like the single textbox form bug in IE.

To get around it, you can use Javascript to handle the enter key press, or just insert a blank hidden textbox. Lame, I know.

Josh Stodola
Thanks a lot! Your posted link describes the exact problem - one form has only one text box, and the other (that works) has two. I'm going to try on Monday but I feel it's going to work. Good job, thanks a bunch!
Andrey
+1  A: 

I suspect that hitting enter is triggering onclick for one of the search buttons in one case and something else in another.

Yes. Browsers may, largely at their whim, treat enter as clicking on a submit-button, just submitting a form, or nothing. Put general form submission stuff in form.onsubmit, rather than an onclick on the first submit button.

bobince
A: 

I think I may help you much If you provide your two forms code. However, check to see for the following submit button code:

<input type="submit" value="Submit">

When you use this, then when you press Enter among the corresponding form, the form will be submitted. If you wish to check something before submitting you can use JavaScript Function like the following:

<input type="button" onclick="javascript_function_name();" value="Submit">

Thanks. If this can not help you, please express the situation more briefly.

Tareq
There is an image button that submits the form: <input type='image'>Unfortunately I can't provide the forms, they both are huge, like 500k each
Andrey