get form input fields with jQuery


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. $('#myForm').submit(function() {
  2. // get all the inputs into an array.
  3. var $inputs = $('#myForm input, #myForm textarea, #myForm select');
  4.  
  5. // not sure if you wanted this, but I thought I'd add it.
  6. // get an associative array of just the values.
  7. var values = {};
  8. $inputs.each(function(i, el) {
  9. values[el.name] = $(el).val();
  10. });
  11.  
  12. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.