Solved

Get jQuery select options value with multiple <select>

Posted on 2013-12-12
4
578 Views
Last Modified: 2013-12-13
Hi,

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
0
Comment
Question by:Victor Kimura
4 Comments
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 166 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
0
 
LVL 43

Accepted Solution

by:
Chris Stanyon earned 167 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

0
 
LVL 16

Assisted Solution

by:hankknight
hankknight earned 167 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

0
 

Author Closing Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

867 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

16 Experts available now in Live!

Get 1:1 Help Now