get all form values using jQuery

Most of you might already know, but this is to whom doesn’t even aware of this method.

Official documentation here : http://api.jquery.com/serialize/

I stumbled upon this method a few years ago, where i had around 20 inputs in a form and want to get all the values and send to form. I used traditional $(‘#id’).val() x no-of-form-input times and ended up with big messy code.

Then i searched all over to see that this method is there for rescue. It will simply take all values as query string, which is easy to pass via ajax.

All you need to do is : $(“#form_id”).serialize() and it will display output as a=1&b=2 etc.

jQuery helps me a lot and this is one is real time saver.

Advertisements

If you have any queries feel free to write to author

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s