Techiio-author
Started by Debarghya DasSep 21, 2021

Open
Convert form data to JavaScript object with jQuery

2 VIEWES 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 2 VIEWES SHARE

How do I convert all elements of my form to a JavaScript object?

I'd like to have some way of automatically building a JavaScript object from my form, without having to loop over each element. I do not want a string, as returned by $('#formid').serialize();, nor do I want the map returned by $('#formid').serializeArray();

1 Replies

Techiio-commentatorSoumya Parida replied 2 days ago0 likes0 dislikes

you can use this:-

function form_to_json (selector) {

var ary = $(selector).serializeArray();

var obj = {};

for (var a = 0; a < ary.length; a++)obj[ary[a].name] = ary[a].value;

return obj;

}

You must be Logged in to reply
Trending Technologies
15
Software40
DevOps46
Frontend Development24
Backend Development20
Server Administration17
Linux Administration26
Data Center24
Sentry24
Terraform23
Ansible83
Docker70
Penetration Testing16
Kubernetes21
NGINX20
JenkinsX17
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance