javascript - Reading selected value of dropdown list in HTML by jQuery - Stack Overflow

I am trying to read the value of the selectedID in a drop down list in html through jQuery but it keeps

I am trying to read the value of the selectedID in a drop down list in html through jQuery but it keeps producing an error. Did I miss something?

<select style="width: 80px;" class="text ui-widget-content ui-corner-all" id="metaList">
<option value="4d5e3a8c418416ea16000000">Wikipedia</option>  
<option value="4d5e3a8c418416ea16010000">Twitter</option>  
<option value="4d5e3a8c418416ea16020000">DBPedia</option>  
<option value="4d64cd534184162629000000">test</option>          
</select>        

I tried which used to work before

var temp = $("#metaList").val(); 

but it produces NULL!

I am trying to read the value of the selectedID in a drop down list in html through jQuery but it keeps producing an error. Did I miss something?

<select style="width: 80px;" class="text ui-widget-content ui-corner-all" id="metaList">
<option value="4d5e3a8c418416ea16000000">Wikipedia</option>  
<option value="4d5e3a8c418416ea16010000">Twitter</option>  
<option value="4d5e3a8c418416ea16020000">DBPedia</option>  
<option value="4d64cd534184162629000000">test</option>          
</select>        

I tried which used to work before

var temp = $("#metaList").val(); 

but it produces NULL!

Share Improve this question edited Feb 23, 2011 at 12:14 Gordon 317k76 gold badges546 silver badges565 bronze badges asked Feb 23, 2011 at 11:58 Ahmad FaridAhmad Farid 14.8k45 gold badges98 silver badges138 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

Your function call is correct, but nothing is selected. That is the reason why NULL is returned.

Try:

var temp = $("#metaList option:selected").val(); 

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745344846a4623495.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信