I have a .click() function on a submit button in a form:
$("#submitId").click(function () {
$('#hiddenInput').val(someVariable);
});
It works like a charm. When the submit button is clicked the click() function fills the hidden input variable and then the whole form gets submitted. The server then receives the hidden input with the refreshed content.
My question is: will it always work? Is there any danger that, by some reason not yet known to me, the submit operation gets executed first and the click() function later? I want to make sure the hidden input always gets refreshed.
enter
will cause the click handler to execute. But if the focus is on one of the form fields,enter
will bypass the click handler, because there was no interaction with the button (just with the form). I think. – Nazarius