John, I think that this is a very common way to set the selection, and might end up breaking people's code when they upgrade to jQuery 1.4. People probably figured out that you could set the selection with either property and used this in their code. When these people upgrade to jQuery 1.4, their code will break and they won't know why! People have a different value property and display value all the time. It seems weird that their code will work when either one of these properties is defined but not both.
Devon On Dec 22, 2:05 am, John Resig <jere...@gmail.com> wrote: > Just to clarify then, since jQuery already covers cases 2-4 as you're > expecting it to and case #1 currently fails - and that case is > decidedly not what this thread discussion started as. > > > Consider the following cases: > > > #1) > > <select id="x"> > > <option value="1">Dummy</option> > > <option value="">Empty</option> > > </select> > > > $('#x').val('') > > should select the second option. > > Agreed. > > > #2) > > <select id="x"> > > <option value="x">z</option> > > <option value="y">x</option> > > </select> > > > $('#x').val('x') > > should select the first option only. > > Yep, as it does in 1.4. > > > #3) > > <select id="x"> > > <option value="x">y</option> > > <option>y</option> > > </select> > > > $('#x').val('y') > > should select the second option only. > > Yep, as it does in 1.4. > > > #4) > > <select multiple id="x"> > > <option value="x">z</option> > > <option value="y">x</option> > > </select> > > > $('#x').val('x') > > should select the first option only, IMO. It's kind of ambiguous and > > jQuery should define what it wants to do. > > Yep, as it does in 1.4. In fact, 1.4 removes the ambiguity completely > by only using the value with the val method, which is much better. To > Devon: The change was very much intentional, as it was the case was > far too ambiguous and it was causing other problems to pop up. A very > explicit note will be made in the 1.4 release notes concerning this > change. > > Revisiting the logic for getting the select val it looks like the || > this.text was a holdover from trying to fix an IE 6 bug: If you don't > specify a value it'll supply "" as the value instead of the option > text. I've re-worked the logic to work uniformly in all browsers. > > Filed and fixed:http://dev.jquery.com/ticket/5697 > > I also went through the logic for .val() on checkboxes and radios - > the revised logic there definitely didn't make sense, especially since > this.value will never be empty (not specifying a value will just > result in a value of "on" - and specifying an empty value is a case we > want to hit). > > Filed and fixed:http://dev.jquery.com/ticket/5698 > > Of course, it would be easy if that was the case but Webkit returns "" > if you don't specify a value attribute, instead of "on". > > Filed and fixed:http://dev.jquery.com/ticket/5699 > > --John -- You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-...@googlegroups.com. To unsubscribe from this group, send email to jquery-dev+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en.