Solved

jQuery get selected item

Posted on 2012-04-09
2
568 Views
Last Modified: 2012-06-22
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>
0
Comment
Question by:JPERKS1985
2 Comments
 
LVL 16

Expert Comment

by:HagayMandel
Comment Utility
var accountcode = $('select#accountdropdown:selected').text();
0
 
LVL 9

Accepted Solution

by:
alex_code earned 500 total points
Comment Utility
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

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now