HTML - Which form element triggered the submission

I am debugging a weird problem with two simlar search forms - when a user enters some search criteria in a textbox and hits enter, one form returns results and the other just reloads. And this only happens in IE - FF treats both forms as expected. I suspect that clicking a button triggers an onclick for one of the search buttons in one case and something else in the other.

How do I know which form element triggered the submit event?

Thank you, Andrey

+2


source to share


4 answers


Sounds like a single text box form error in IE .



To get around this, you can use Javascript to handle the enter key press, or just insert an empty hidden text box. Hmm, I know.

+1


source


I suspect that clicking a button triggers an onclick for one of the search buttons in one case and something else in the other.



Yes. Browsers can, mostly on a whim, treat input by hitting the submit button, just submitting a form, or nothing. Put the generic form submission stuff in form.onsubmit, not onclick on the first submit button.

+1


source


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

There might be a way to just have an onsubmit () form so you can retrieve the trigger item from the event object, but I'd have to dive into the docs to see if this is possible ... if I get a chance I'll look.

0


source


I think I can help you. If you provide your form code. However, check if there is the following submit button code:

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

      

When you use this, then when you press Enter on the appropriate form, the form will be submitted. If you want to test something before submitting, you can use a JavaScript function like below:

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

      

Thank. If that doesn't help you, please summarize the situation.

0


source







All Articles