Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

jQuery get selected item

Posted on 2012-04-09
2
Medium Priority
?
647 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 16

Expert Comment

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

Accepted Solution

by:
Alex earned 2000 total points
ID: 37827049
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
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)
Suggested Courses

670 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