Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I exclude certain form fields upon submission of the form without disabling the field

If I have a form with the following 3 fields:

First Name Last Name Date Of Birth

When the user fills in all 3 fields and submits you will get the URL

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

However, if the user only fills in First Name and Date Of Birth you will get

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

How do I achieve

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

I don't want to disable the input field upon using onsubmit. Is there a better way than disabled the input field?

Please help...

like image 879
Daurice Avatar asked Feb 02 '11 01:02

Daurice


People also ask

How do you hide form fields based upon user selection?

The Javascript uses jQuery to change the DOM depending on the selections made. Essentially, depending on the conditions of a field answer, you can bulk turn show/hide other components of the form. For validation purposes, some extra attributes are changed depending on the selection.


1 Answers

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

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

// native Javascript
document.getElementById('inputId').removeAttribute('name');
like image 110
Simon Borsky Avatar answered Oct 13 '22 03:10

Simon Borsky