Just wondering if there is anything built-in to Javascript that can take a Form and return the query parameters, eg: "var1=value&var2=value2&arr[]=foo&arr[]=bar..."
I've been wondering this for years.
Just wondering if there is anything built-in to Javascript that can take a Form and return the query parameters, eg: "var1=value&var2=value2&arr[]=foo&arr[]=bar..."
I've been wondering this for years.
If you don't want to use a library, this should cover most/all of the same form element types.
Is is probably too late to answer your question.
I had the same question and I didn't like to keep appending strings to create a URL. So, I started using $.param as techhouse explained.
I also found a URI.js library that creates the URLs easily for you. There are several examples that will help you: URI.js Documentation.
Here is one of them:
If you're using jQuery you might want to check out
jQuery.param()
http://api.jquery.com/jQuery.param/Example:
querystring can help.
So, you can
Without jQuery
For browsers that don't support arrow function syntax which requires ES5, change the
.map...
line toWith jQuery you can do this by
$.param