jquery - How can I get all elements of the selected form -
Hello we say that I have two forms on one page.
Now I want to get all input elements (even if they are hidden).
Now I see such a code:
$ ("form.prev, form.next"). Submit (function (e) {e.preventDefault (); var input = $ (this) .filter (': input'); console.log (input); var value = {}; inputs.each (function () { Value [this .name] = $ (this) .val ();}); console.log (value);});
I hope to see the list of input elements with their keys and values, but the result of console.log (value);
is an empty object
What's going wrong here?
Do not have to do it yourself - for this purpose serialize ()
The function was invented.
$ ("Form.prev, form.next"). Submit (function (e) {e.preventDefault (); var data = $ (this) .serialize (); // data is a key / value string, you can now use it in AJAX requests for example });
Comments
Post a Comment