Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I check to see if my <select> element contains the multiple attribute

hi I have tried many options to check if the multiple attribute is set in my select box but none have worked. I am trying to determine if the current select box that I am getting values from is a multiple select so far this is what I have tried:

if($(":select[multiple]").length){
           alert("worked");
}

also

if($("select").attr("multiple"){
           alert("worked");
}

also

if($("select").attr("multiple") != 'undefined'{
           alert("worked");
}

html:

<select multiple="multiple" style="height:50px" class="classname" name="multi_values[]"> 
 <option value="blah">blah</option> 
 <option value="blah">blah</option> 
 <option value="blah">blah</option>              
</select>
like image 294
arrowill12 Avatar asked Jul 03 '12 17:07

arrowill12


1 Answers

remove : at the beginning of :

if($("select[multiple]").length){
    alert("worked");
}

Demo : http://jsfiddle.net/D5JX5/

like image 189
mgraph Avatar answered Oct 12 '22 23:10

mgraph