javascript - getElementsByTagName for a specific form in jquery -


i'm trying write generic javascript function (using jquery) acquire input elements on specific form - , return them json.

function getformdataasjson(sformid) {     // read input attributes form; return json      var form = $(sformid);     if (form != null)     {         var inputs = $('input', form);         var json = {};          for(i = 0; < inputs.length; ++i)         {             var next = inputs[i];             var key  = $(next).attr('id');             var val  = $(next).val();              if( val != null && key != null)                 json[key] = val;         }          return json;     } } 

the error above in line:

var inputs = $('input', form); 

where form form object. how can input elements in given form?

$("form").each(function(){ $(this).find(':input') //<-- should return input elements in specific form. }); 

or can use

var form = $('#'+sformid); 

this you.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -