Created
June 21, 2013 18:01
-
-
Save venblee/5833066 to your computer and use it in GitHub Desktop.
Get Value or Text from Select2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var test = $('#test'); | |
$(test).select2({ | |
data:[ | |
{id:0,text:"enhancement"}, | |
{id:1,text:"bug"}, | |
{id:2,text:"duplicate"}, | |
{id:3,text:"invalid"}, | |
{id:4,text:"wontfix"} | |
], | |
width: "300px" | |
}); | |
$(test).change(function() { | |
//var theID = $(test).val(); // works | |
//var theSelection = $(test).filter(':selected').text(); // doesn't work | |
var theID = $(test).select2('data').id; | |
var theSelection = $(test).select2('data').text; | |
$('#selectedID').text(theID); | |
$('#selectedText').text(theSelection); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment