Robin
Robin

Reputation: 313

Is it bad practice to autosubmit a form with javascript?

My development department is in an argument about autosubmitting a form with javascript when all elements are filled in. We've got a form with 2 select-elements, which we currently submit is both are selected.

What are some good pro and con arguments for autosubmitting a form with javascript? The only real argument we've came up with so far is that the user can't easily correct it's selection if the form is autosubmitted: he'll have to go back to the previous page where the form is located. However, if the user does fill in the form correctly, it might save him some time (half a second maybe, but still).

Upvotes: 1

Views: 334

Answers (3)

Shadow Wizard
Shadow Wizard

Reputation: 66388

To "fix" the argument you mentioned (which is indeed good one) you can add confirm dialog before auto submitting:

if (confirm('Are the values correct?'))
   myForm.submit();

Apart of that, nothing wrong in my opinion in auto submitting.

Upvotes: 0

Alexander Ivanov
Alexander Ivanov

Reputation: 717

Autosubmiting plays well when you load results dynamically into the current page, but still you should not rely on this. About your case - definitely no.

Upvotes: 2

Quentin
Quentin

Reputation: 943751

It is unexpected behaviour. Selections (confusing exceptions aside) do not submit forms. Clicking a submit button submits forms.

Upvotes: 6

Related Questions