How to stop an input field in a form from being submitted with JavaScript?

Spread the love

Sometimes, we want to stop an input field in a form from being submitted with JavaScript.

In this article, we’ll look aty how to stop an input field in a form from being submitted with JavaScript.

How to stop an input field in a form from being submitted with JavaScript?

To stop an input field in a form from being submitted with JavaScript, we set the name property of the field we don’t want to submit to an empty string.

For instance, we write

document.getElementById("TheInputsIdHere").name = "";
document.getElementById("TheFormsIdHere").submit();

to get the input with getElementById and set its name to an empty string to stop it from being submitted.

Then we get the form with getElementById and call submit to submit the form.

Conclusion

To stop an input field in a form from being submitted with JavaScript, we set the name property of the field we don’t want to submit to an empty string.

Leave a Reply

Your email address will not be published. Required fields are marked *