How can I exclude certain form fields when submitting a form without disabling the field

If I have a form with the following three fields:

First name Last name Date of birth

When the user fills in all 3 fields and sends, you will receive a URL

http: //fakeURL.php?firstName=Fred&lastName=Flintstone&DateOfBirth=2/5/1952

However, if the user fills in only the name and date of birth, you will receive

http: //fakeURL.php?firstName=Fred&lastName=&DateOfBirth=2/5/1952 (where lastName has no value)

How to reach

http: //fakeURL.php?firstName=Fred&DateOfBirth=2/5/1952 (where lastName and value are removed from the URL)

I do not want to disable the input field when using onsubmit. Is there a better way than turning off the input field?

Please, help...

+8
source share
3 answers

Just remove the "name" attribute from the input element.

// using jQuery
$('#inputId').removeAttr('name');

// native Javascript
document.getElementById('inputId').removeAttribute('name');
+17
source

You should:

  • Remove or disable the field from the form before submitting.
  • , URL-, .
  • AJAX ,

, GET, URL-. HTML HTTP.

+5

GET , .

, ( , - ), POST .

-1

All Articles