From: Brandon Aaron Date: Fri, 12 Oct 2007 12:51:07 +0000 (+0000) Subject: Fixed .val(String) for select elements (#1760) [Thanks Sam] X-Git-Tag: 1.2.2b~92 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=971840f343dae04fdc6ff51ecb03ec8b3aaee067;p=jquery.git Fixed .val(String) for select elements (#1760) [Thanks Sam] --- diff --git a/src/core.js b/src/core.js index 9fd0168e6..b3b0a9d27 100644 --- a/src/core.js +++ b/src/core.js @@ -407,7 +407,7 @@ jQuery.fn = jQuery.prototype = { jQuery.inArray( this.text, values ) >= 0); }); - if ( !tmp.length ) + if ( !values.length ) this.selectedIndex = -1; } else diff --git a/test/unit/core.js b/test/unit/core.js index 32ff83e86..eee1740d6 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -824,11 +824,14 @@ test("val()", function() { }); test("val(String)", function() { - expect(2); + expect(3); document.getElementById('text1').value = "bla"; ok( $("#text1").val() == "bla", "Check for modified value of input element" ); $("#text1").val('test'); ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" ); + + $("#select1").val("3"); + ok( $("#select1").val() == "3", "Check for modified (via val(String)) value of select element" ); }); test("html(String)", function() {