2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

Get all the input field values from specific form using JQuery

I have a html form which contain multiple input texts,selects etc.

Now I need to validate each form by getting its ids dynamically.

so is there any way to populate the input from certain form id? eg if i click submit button from certain form id, then jquery will populate for me all of the input within those form id. currently what i"m doing is like this:

$("form").submit(function(){ return validateForm($(this)) });
function validateForm(form){
var retVal = true;
var re;
$.each(form.serializeArray(), function(i, field) {
  var input = $("input[name="+field.name+"]");
  field.value = $.trim(field.value);
  switch(field.name){
    case "name" :
        and another cases...
      }
    })
 }

that was work, but in that case, i only get the field.name and field.value, and actually what i want is, i want a jquery object for each input element, so i can access their css, id, name, and even animate those input element

is there any way for this?

userimage

You can able achieve  in a simpler way like below,

$("form#formID :input").each(function(){
 var input = $(this); // This is the jquery object of the input, do what you will
});


From this you can able to get the ids of each inputs and by using the jquery api you can able to do what ever required.



Answer is