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
JavaScriptjQueryHTML

Avatar of undefined
Last Comment
Gary

8/22/2022 - Mon
Dave Baldwin

What are you talking about?
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
leakim971

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Gary

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!
Your help has saved me hundreds of hours of internet surfing.
fblack61