jQuery get selected item

I have a form with a simple dropdown box.

I'm trying to use jQuery to get the value of the currently selected item.

I've tried,
var accountcode = $('select#accountdropdown').val();

var accountcode = $('select#accountdropdown:selected').val();

and a few other variations and no matter the change I still get only the first value in the drop down box even if it's not selected. For instance CODE1 will always be returned.



<select name="shippingdropdown" id="shippingdropdown" class="large-input">
<option value="CODE1">C1</option><
option value="CODE2">C2</option>
<option value="CODE3">C3</option>
</select>
LVL 1
JPERKS1985Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
AlexConnect With a Mentor Software EngineerCommented:
You need to work with change function and the val() of the select box. Try the following:

$('#shippingdropdown').change(function(){

       var get_the_selected_value=$(this).val();
       alert(get_the_selected_value);

    });
0
 
HagayMandelCommented:
var accountcode = $('select#accountdropdown:selected').text();
0
All Courses

From novice to tech pro — start learning today.