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

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -