jquery - Javascript : How to properly check if selected option is empty? -


i have selected option here, don't know why if didn't choose option means (-select-) values="" no values, still not work. select option array because on loop.

here code

var randomgender_arr = []; var tae = true; if(randgender == 'random'){     $('select[name="randomgender[]"]').each(function(k,v){          if($(v).val()===''){             alert('please select gender')         }else{             randomgender_arr.push($(v).val());         }      }); }else{  } 

btw selected option here, can see first option disabled. how consider empty? , check if when leave 1 of the option (-select-) return false.

echo'<div style="float:right; position:absolute; top:10px; right:0;"> <label for="randomgender">gender:</label>     <select name="randomgender[]" id="randomgender" class="form-control randomgender">         <option disabled readonly selected>-select-</option>         <option value="male">male</option>         <option value="female">female</option>     </select> </div> <div style="clear:both;"></div>'; 

let changetime = 0;    let opt = document.queryselector(".opt");    let submit = document.queryselector(".submit");    let notif = document.queryselector(".notif");    opt.addeventlistener("change",function(){    changetime++;  });    submit.addeventlistener("click",function(){      if(changetime != 0){      // success      notif.textcontent = "success";          }else{      notif.textcontent = "please chose @ less 1 time!";    }      });
<div class="opt" style="float:right; position:absolute; top:10px; right:0;">  <label for="randomgender">gender:</label>      <select name="randomgender[]" id="randomgender" class="form-control randomgender">          <option disabled readonly selected>-select-</option>          <option value="male">male</option>          <option value="female">female</option>      </select>  </div>  <div style="clear:both;"></div>  <button class="submit">button</button>  <p class="notif"></p>


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -