Link to home
Start Free TrialLog in
Avatar of freshgrill
freshgrill

asked on

Remove empty post variables with no value

Want to remove empty post variables with no value, need to update windows  URL with shorten version.

Prefer lightest method, can use jquery but would like an answer without any library if possible
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

What are you talking about?
Avatar of freshgrill
freshgrill

ASKER

Sorry, it should be Get method. When a user submits a form using the get method, we want to remove all the empty variables and have the url show only the variables that have values (were selected).
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
For a jQuery version

$("#myform").submit(function(){
	$('input,select', this).each(function(){
		if($(this).val() == "") $(this).remove();
	})
})

Open in new window

http://jsfiddle.net/GaryC123/S9eMJ/2/

I like leakim's idea of just removing the name attribute!