html - JavaScript element validation -


this question has answer here:

i wish check if in multiple dropdown list has been selected using javascript.

<select name="id" id="id" size=22 multiple > 

and if checkboxes has been checked

<input type="checkbox" name="inst" class="asa" value="inst1">  <input type="checkbox" name="inst" class="asa" value="inst2"> 

try code

demo

var selectval = document.getelementbyid('id'); var selectcount = 0; var values = []; (var = 0; < selectval.options.length; i++) {   if (selectval.options[i].selected) {     selectcount++;     values.push(selectval.options[i].value);   } } 

for checkbox

<input type="checkbox" name="inst" class="asa" id="check1" value="inst1">  <input type="checkbox" name="inst" class="asa" id="check2" value="inst2">  var check1 = document.getelementbyid("check1").checked; alert(check1); var check2 = document.getelementbyid("check2").checked; alert(check2); 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -