How to get <select> options either (value or text) using jQuery
Posted
by Muhammad Sajid
on Stack Overflow
See other posts from Stack Overflow
or by Muhammad Sajid
Published on 2009-12-17T10:18:34Z
Indexed on
2010/04/10
12:43 UTC
Read the original article
Hit count: 270
jQuery
Hello,
i have a code for
<select id='list'>
<option value='1'>Option A</option>
<option value='2'>Option B</option>
<option value='3'>Option C</option>
</select>
and i want that how ever i select any option, it will show in an alert message. i have try
<script type='text/javascript'>
//var value = $("#list option[value=2]").text();
//var value = $("#list option:selected").text();
//var value = $('#list').val();
var value = $(this).val();
alert(value);
</script>
but fail.
© Stack Overflow or respective owner