Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Get jQuery select options value with multiple <select>

Posted on 2013-12-12
Medium Priority
Last Modified: 2013-12-13

I have this code:

$(".relation_to_grantor").change(function(this) {

 var sGRelationToGrantorSelection = $(this).val();


I'm wondering if I have multiple select tags with the class"relation_to_grantor" like:

<select class="relation_to_grantor">

and I changed, say, the first <select> that matches this class name then how would I just get the options value for just this select that I changed?

Is the above code, right? I haven't test it yet.

Thank you
Question by:Victor Kimura
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
LVL 82

Assisted Solution

leakim971 earned 664 total points
ID: 39714468
Is the above code, right? I haven't test it yet.

Yes, you're using the keyword this which represents the select that triggered the change event
LVL 44

Accepted Solution

Chris Stanyon earned 668 total points
ID: 39714645
You shouldn't pass this as an argument of the function - that's for passing the event, not the control!

Your code should look like this:

$(".relation_to_grantor").change(function() {
    var sGRelationToGrantorSelection = $(this).val();

Open in new window

LVL 16

Assisted Solution

hankknight earned 668 total points
ID: 39715552
You could use "option:selected" like this:

var sGRelationToGrantorSelection;
$(".relation_to_grantor").change(function () {
 sGRelationToGrantorSelection = $(this).find('option:selected').attr('value');

Open in new window


Author Closing Comment

by:Victor Kimura
ID: 39717870
Ok. Thanks, fellows!

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
The viewer will learn how to dynamically set the form action using jQuery.
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…
Suggested Courses

610 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