asifa
asifa

Reputation: 771

how to get the value of the dropdown jquery

I want to get the value of the dropdown. I am using msDropDown, but i am getting its value as undefined. The html as follows:

 <select name="category[]" 
         id="webmenus_<?php echo $BPackageCityRelatedToCountry[$i]['city_id']; ?>"      
         onchange="showValue(this.value)"
 >
     <option value="0" selected="selected" title="Please select hotel category"></option>
     <option value="5_<?php echo $BPackageCityRelatedToCountry[$i]['city_id']; ?>" title="/public/front_end/images/5star.png"></option>
     <option value="4_<?php echo $BPackageCityRelatedToCountry[$i]['city_id']; ?>" title="/public/front_end/images/4star.png"></option>
     <option value="3_<?php echo $BPackageCityRelatedToCountry[$i]['city_id']; ?>" title="/public/front_end/images/3star.png"></option>
     <option value="2_<?php echo $BPackageCityRelatedToCountry[$i]['city_id']; ?>" title="/public/front_end/images/2star.png"></option>
     <option value="1_<?php echo $BPackageCityRelatedToCountry[$i]['city_id']; ?>" title="/public/front_end/images/1star.png"></option>
</select>

jquery alert($("input[name='category[]']").val()); alerts as undefined.

How can i get the value of the dropdown? Thanks,

Upvotes: 0

Views: 186

Answers (3)

happytor
happytor

Reputation: 31

$(":input[name='category[]']").val()

Upvotes: 2

donald123
donald123

Reputation: 5749

You use select instead of input

Edit your HTML and set the select Tag to mutiple

 <select name="test" multiple>
     <option value="1">ITEM 1</option>
      <option value="2">ITEM 2</option>
      <option value="3">ITEM 3</option>
  </select>

alert($('select[name="test"]').val());
// outputs 1,2,3 when you select all three options

Upvotes: 1

NullPoiиteя
NullPoiиteя

Reputation: 57332

try

 $("class of select ").change(function() {
        alert($(this).val());
    });

Upvotes: 1

Related Questions