jquery - If/else statement: Search through multiple possible values only finds last value (javascript) -


i have form various inputs search address. province , postal code first appear when load page, there option open toggle display more options such street name etc. basically, i'm trying achieve toggle remain open when page loads again if select , text inputs not empty (' ' , 0).

i have of logic down, problem if/else statement looking @ last value getting.

var allinputsvalue; var allinputs; //for testing purposes  $('.address-options').each(     function(){         allinputs = $(this); //for testing purposes         allinputsvalue = $(this).val();         //console.log('type: ' + allinputs.attr('type') + ' name: ' + allinputs.attr('name') + ' value: ' + allinputs.val());         //console.log(' id: ' + allinputs.attr('id') + '\n' + ' value: ' + allinputs.val());         console.log('value: ' + allinputsvalue);     } );  //if($('#civicno').val() == '', $('#streetname').val() == ''){ if(allinputsvalue === '' || allinputsvalue === 0){     alert("empty fields");     if (localstorage) {         localstorage.setitem('addressoptions', 'closed');     }     togglepane("closed"); }else{     alert("fields not empty");      if (localstorage) {         localstorage.setitem('addressoptions', 'open');     }     togglepane("open"); } 

i'm trying keep code clean without having else if every input id.

in console log correct values looking for. missing?

you need put if-else inside .each

var allinputsvalue;     var allinputs; //for testing purposes      $('.address-options').each(             function(){                 allinputs = $(this); //for testing purposes                 allinputsvalue = $(this).val();                 //console.log('type: ' + allinputs.attr('type') + ' name: ' + allinputs.attr('name') + ' value: ' + allinputs.val());                 //console.log(' id: ' + allinputs.attr('id') + '\n' + ' value: ' + allinputs.val());                 console.log('value: ' + allinputsvalue); //if($('#civicno').val() == '', $('#streetname').val() == ''){     if(allinputsvalue === '' || allinputsvalue === 0){         alert("empty fields");         if (localstorage) {             localstorage.setitem('addressoptions', 'closed');         }         togglepane("closed");     }else{         alert("fields not empty");          if (localstorage) {             localstorage.setitem('addressoptions', 'open');         }         togglepane("open");     }             }     ); 

Comments

Popular posts from this blog

html - height not adding height to a empty div -

Oracle SQL. How to select specific IDs where value of columns specify criteria? -

python - Robot Framework location and name of keyword -