From: John Resig Date: Sun, 8 Jul 2007 16:28:45 +0000 (+0000) Subject: Added support for "first option is auto-selected in a drop-down" functionality. X-Git-Tag: 1.1.4~79 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6f0c9a5fd751d590be07e890758b8229e630413d;p=jquery.git Added support for "first option is auto-selected in a drop-down" functionality. --- diff --git a/build/runtest/env.js b/build/runtest/env.js index f4c54bb4b..23b413640 100644 --- a/build/runtest/env.js +++ b/build/runtest/env.js @@ -305,6 +305,27 @@ var window = this; set checked(val) { return this.setAttribute("checked",val); }, get selected() { + if ( !this._selectDone ) { + this._selectDone = true; + + if ( this.nodeName == "OPTION" && !this.parentNode.getAttribute("multiple") ) { + var opt = this.parentNode.getElementsByTagName("option"); + + if ( this == opt[0] ) { + var select = true; + + for ( var i = 1; i < opt.length; i++ ) + if ( opt[i].selected ) { + select = false; + break; + } + + if ( select ) + this.selected = true; + } + } + } + var val = this.getAttribute("selected"); return val != "false" && !!val; },