javascript - How to detect whether an html input object is a button or not? -


i working on trying pull inputs form, excluding buttons, not radio buttons. getting inputs via .find() method of form element. have inputs, unable restrict them inputs other submit button or similar button. have tried jquery .is(), .type(), both no luck suggestions/ references helpful have not found of yet. here code using pull forms.

 var inputs = formlist.find(":input");           if (inputs ? inputs.length > 0 : false)         {           for(j = 0;j < inputs.length; j++)           {               console.log("input: " + inputs[j]);               if (inputs[j].name != "")               {                   webforms.push({"inputname": inputs[j].name});                 }else if (inputs[j].id != "")               {                  webforms.push({"inputname": inputs[j].id});                 }            }          } 

like said, have tried .is , .type no luck. here example of how using .is()

var formlist = $("form"); var formname = $("form").attr("name"); if (formlist != null ? formlist.length > 0 : false) {   if (formlist.length < 2)   {     if (formlist.attr("name") ? formlist.attr("name") != "" : false)     {       //alert("form name not null");         //alert("form name: " + formlist.attr("name"));         var webforms = [];         //alert("formlist name: " + formlist[i]);         var inputs = formlist.find(":input");           if (inputs ? inputs.length > 0 : false)         {           for(j = 0;j < inputs.length; j++)           {               console.log("input: " + inputs[j]);               if (inputs[j].name != "")               {                   if(inputs[j].is(":button"))                  {                      console.log(inputs[j].name + " button");                  }                  webforms.push({"inputname": inputs[j].name});                 }else if (inputs[j].id != "")               {                  if(inputs[j].is(":button"))                  {                      console.log(inputs[j].name + " button");                  }                  webforms.push({"inputname": inputs[j].id});                 }            }          }         //alert(json.stringify(webforms));         jsonform.forms[jsonform.forms.length - 1].name = formlist.attr("name");         //alert("json form name: " + json.stringify(jsonform));         jsonform.forms[jsonform.forms.length - 1].inputs = webforms;         //alert("name: " + jsonform.forms[jsonform.forms.length - 1].name);         }    } 

any here appreciated.

you can use following code input elements aren't buttons or inputs type attribute of "submit".

 var inputs = formlist.find(':input:not(button, [type="submit"])'); 

here live demonstration.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -