aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/attributes/val.js3
-rw-r--r--test/unit/attributes.js9
2 files changed, 9 insertions, 3 deletions
diff --git a/src/attributes/val.js b/src/attributes/val.js
index b01eebff7..b13641b28 100644
--- a/src/attributes/val.js
+++ b/src/attributes/val.js
@@ -118,12 +118,13 @@ jQuery.extend({
set: function( elem, value ) {
var optionSet, option,
options = elem.options,
+ values = jQuery.makeArray( value ),
i = options.length;
while ( i-- ) {
option = options[ i ];
- if ( jQuery.valHooks.option.get( option ) === value ) {
+ if ( jQuery.inArray( jQuery.valHooks.option.get( option ), values ) >= 0 ) {
// Support: IE6
// When new option element is added to select box we need to
diff --git a/test/unit/attributes.js b/test/unit/attributes.js
index 2b2eee425..ff89b444e 100644
--- a/test/unit/attributes.js
+++ b/test/unit/attributes.js
@@ -928,7 +928,7 @@ if ( "value" in document.createElement("meter") &&
}
var testVal = function( valueObj ) {
- expect( 8 );
+ expect( 9 );
jQuery("#text1").val( valueObj("test") );
equal( document.getElementById("text1").value, "test", "Check for modified (via val(String)) value of input element" );
@@ -943,7 +943,9 @@ var testVal = function( valueObj ) {
equal( document.getElementById("text1").value, "", "Check for modified (via val(null)) value of input element" );
var j,
- $select1 = jQuery("#select1");
+ select = jQuery( "<select multiple><option value='1'/><option value='2'/></select>" );
+ $select1 = jQuery("#select1"),
+
$select1.val( valueObj("3") );
equal( $select1.val(), "3", "Check for modified (via val(String)) value of select element" );
@@ -959,6 +961,9 @@ var testVal = function( valueObj ) {
j.val( valueObj( "asdf" ) );
equal( j.val(), "asdf", "Check node,textnode,comment with val()" );
j.removeAttr("value");
+
+ select.val( valueObj( [ "1", "2" ] ) );
+ deepEqual( select.val(), [ "1", "2" ], "Should set array of values" );
};
test( "val(String/Number)", function() {