Skip to content

JavaScript submit form excluding fields

I have a simple html form:

<form action="test" method="post" id="myForm">
    <input type="text" name="myTextField">
    <input type="text" name="myTextField2">
    <input type="text" name="dontSubmitThisField">

And I need to submit it with JavaScript, but I want to exclude the dontSubmitThisField field from the request. Is there a way of doing that without Ajax?



Just disable the field.

Either do it via HTML if the field cannot be updated by the user:

Or do it via jQuery with a on submit event:

    $('input[name="dontSubmitThisField"]').prop('disabled', true);