I''m trying to select an option in a listbox. <select> <option id="apple">Apple</option> <option id="orange">Orange</option> <option id="pineapple" selected="selected">Pineapple</option> <option id="banana">Banana</option> </select> $(''apple'').setAttribute("selected", "selected"); for some reason this does not work. Anyone else seen this behavior, knows a way around? All help much appreciated best regards DrBenway --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
It does work in IE but not in FF or Safari --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
I would have thought you had to set the selectedIndex on $(''select'') ? On 25/01/2008, DrBenway <westworld-LPO8gxj9N8aZIoH1IeqzKA@public.gmane.org> wrote:> > It does work in IE but not in FF or Safari > > >-- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
I got this to work by doing $(''yourSelectTagHere'').update(''<option selected="selected">...</ option><option>...</option>'') (read that innerHTML will not work on select tags, so you should use update()) IE, FF and Safari seem to like it ^_^ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Have you tried: $(''apple'').writeAttribute(''selected'') ? On Jan 25, 1:58 pm, DrBenway <westwo...-LPO8gxj9N8aZIoH1IeqzKA@public.gmane.org> wrote:> I got this to work by doing > $(''yourSelectTagHere'').update(''<option selected="selected">...</ > option><option>...</option>'') > (read that innerHTML will not work on select tags, so you should use > update()) > IE, FF and Safari seem to like it > > ^_^--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
writeAttribute doesn''t work :/ selectedIndex is the way to go --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Mind opening a ticket ? On Jan 25, 4:23 pm, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> writeAttribute doesn''t work :/ > selectedIndex is the way to go--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 25, 11:36 pm, Tobie Langel <tobie.lan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Have you tried: $(''apple'').writeAttribute(''selected'') ?Why not: $(''apple'').selected = true; -- Rob --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Take the advice of kangax and Richard, To set the selected item of a select box, you use selectedIndex. There is no better way. Setting the selected attribute on an option is not a reliable means of setting the selected state, not to mention it requires you to "unset" the selected attribute on another option. -justin --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 26, 9:26 am, "Justin Perkins" <justinperk...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Take the advice of kangax and Richard, > > To set the selected item of a select box, you use selectedIndex.That is one option.> There is no better way.Depends on your criteria for "better".> Setting the selected attribute on an option is > not a reliable means of setting the selected state, not to mention it > requires you to "unset" the selected attribute on another option.No, it doesn''t. For a single-select element, using script to set an option''s selected attribute to true (i.e. setting the DOM element''s selected property) makes it the currently selected option. <URL: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-70874476 > However, using innerHTML to add a second option element with an HTML selected attribute will cause the document to have invalid markup. How the browser translates that into a DOM is likely browser dependent as it relies on error correction. -- Rob --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
That confirms what I thought. If using writeAttribute doesn''t work, it''s a Prototype bug, and we need to fix it. Could someone kindly verify this behviour and open a ticket ? That would be great. Thanks, Tobie On Jan 26, 12:57 am, RobG <rg...-AFFH1GffN5hPR4JQBCEnsQ@public.gmane.org> wrote:> On Jan 26, 9:26 am, "Justin Perkins" <justinperk...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Take the advice of kangax and Richard, > > > To set the selected item of a select box, you use selectedIndex. > > That is one option. > > > There is no better way. > > Depends on your criteria for "better". > > > Setting the selected attribute on an option is > > not a reliable means of setting the selected state, not to mention it > > requires you to "unset" the selected attribute on another option. > > No, it doesn''t. > > For a single-select element, using script to set an option''s selected > attribute to true (i.e. setting the DOM element''s selected property) > makes it the currently selected option. > > <URL:http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-70874476> > > However, using innerHTML to add a second option element with an HTML > selected attribute will cause the document to have invalid markup. > How the browser translates that into a DOM is likely browser dependent > as it relies on error correction. > > -- > Rob--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 25, 2008 5:57 PM, RobG <rgqld-AFFH1GffN5hPR4JQBCEnsQ@public.gmane.org> wrote:> Depends on your criteria for "better". > No, it doesn''t.I guess I should have clarified that I''m referring to a means to reliably set the selected state for a select box, across all browsers, without branching. -justin --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 26, 12:03 pm, "Justin Perkins" <justinperk...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Jan 25, 2008 5:57 PM, RobG <rg...-AFFH1GffN5hPR4JQBCEnsQ@public.gmane.org> wrote: > > > Depends on your criteria for "better". > > No, it doesn''t. > > I guess I should have clarified that I''m referring to a means to > reliably set the selected state for a select box, across all browsers, > without branching.I expect that both methods are equally reliable across all browsers, there is no need to use one or the other based on the browser. Which one is "best" depends on the circumstance. If the intention is to set say the third option to selected, I''d likely use selectedIndex. If the intention was to set the option with a particular value to selected, I''d iterate over the options collection until I found the option, then set its selected property. -- Rob --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
I have added a ticket http://dev.rubyonrails.org/ticket/10930 So, writeAttribute(''selected'') should set selected to true. Do we still need to assign an attribute via setAttribute(''selected'', ''selected'')? I understand that hasAttribute(''selected'') should return true on such element, but would it actually have any meaning? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 26, 4:52 pm, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have added a tickethttp://dev.rubyonrails.org/ticket/10930 > > So, writeAttribute(''selected'') should set selected to true. Do we > still need to assign an attribute via setAttribute(''selected'', > ''selected'')?No, writeAttribute is a wrapper for the built-in setAttribute method of the DOM 2 Core Element interface. <URL: http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-F68F082 > If the intention is to make a particular option the currently selected option, setAttribute is bad way to go about it. setAttribute (and hence writeAttribute) sets the value of the element''s HTML selected property, which does not set an option element as the currently selected option in some browsers (Safari 3, Firefox 2, Opera 9) but does in others (IE 6). The HTML selected attribute is typically only used to select an option when the HTML is first parsed and when a form is reset if the select is in a form. Hence using setAttribute may well caues multiple option elements to have their selected attribute set to true in a single- select element - the result of that is browser dependent and unreliable as indicated above. You can only reliably set an option to be the currently selected option by either setting the selectedIndex property of the select element OR setting the selected property of the option element directly, i.e.: selectElement.selectedIndex = <some option.index value>; OR optionElement.selected = true; Note that you can also the selectedIndex property it to -1 to have no option selected. Use either of the above methods and hasAttribute(selected) will return false, unless the option element''s selected attribute has been set previously (see below).> I understand that hasAttribute(''selected'') should return > true on such element, but would it actually have any meaning?hasAttribute uses the DOM 2 Core getAttributeNode method, which returns true or false depending on whether a value has been specified for the attribute. In this case, using setAttribute to set the value of the attribute to either ''true'' or ''false'' will cause hasAttribute to return ''true'', since the attribute has been assigned a value, even though the value might be false. So yes, it''s useless for determining whether a particular option is the currently selected option. To do that reliably, you need to either check whether the option''s index property has the same value as the select''s selectedIndex property, or check the selected property of the option directly, e.g. if (optionElement.index == optionElement.parentNode.selectedIndex) or if (optionElement.selected) The second method is reliable if the selected attribute has been set in the source HTML, but unreliable in some browsers if setAttribute has been used to mess with the HTML selected property. The bottom line in all that is: do not use writeAttribute (or setAttribute) to set an option as the currently selected option. Set either the selectedIndex property or the option''s selected property directly. Following is some code, play with it in different browsers - it''s a reall spinout. <select id="xx"> <option id="opt0">zero <option id="opt1" selected>one <option id="opt2">two </select><br> <button onclick=" $(''xx'').selectedIndex = -1; ">(''xx'').selectedIndex = -1</button><br> <button onclick=" $(''xx'').selectedIndex = 2; ">(''xx'').selectedIndex = 2</button><br> <button onclick=" $(''opt2'').writeAttribute(''selected'', ''selected''); ">(''opt2'').writeAttribute(''selected'', ''selected'')</button><br> <button onclick=" $(''opt2'').writeAttribute(''selected'', true); ">(''opt2'').writeAttribute(''selected'', true)</button><br> <button onclick=" $(''opt2'').setAttribute(''selected'',false); ">$(''opt2'').setAttribute(''selected'',false)</button><br> <button onclick=" $(''opt2'').selected = true; ">(''opt2'').selected = true;</button><br> <button onclick=" alert($(''opt2'').hasAttribute(''selected'')); ">alert($(''opt2'').hasAttribute(''selected''))</button><br> <button onclick=" alert($(''opt1'').selected); ">alert(opt1.selected)</button><br> <button onclick=" alert($(''opt2'').selected); ">alert(opt2.selected)</button><br> -- Rob --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Rob, Thanks for a great explanation. I suspect that "checked" has similar quirky behavior? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On 25/01/2008, Justin Perkins <justinperkins-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Take the advice of kangax and Richard, > > To set the selected item of a select box, you use selectedIndex. > > There is no better way. Setting the selected attribute on an option is > not a reliable means of setting the selected state, not to mention it > requires you to "unset" the selected attribute on another option. > > -justin >Just adding a few notes to this questio (not directly in response to Justin''s recommendation). There are effectively 2 type of select boxes. select-multiple and select-single They behave slightly different with regard to the "select" properties. If select-single is used, then $(''select'').selectedIndex is the property to use. If select-multiple is used, then you $(''option_x'').selected is the property to use. With select-multiple, you can set multiple options (you got that, right, from the name select-multiple, right? Yes? <grin>). That is why there is a select property on the option. Having read through the rest of the posts here, I think the multiple select has been ignored and erroneous information about option.selected has been presented. Setting option.selected is perfectly fine if your select is <select multiple><opti....></select> Richard. -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 28, 9:59 pm, "Richard Quadling" <rquadl...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 25/01/2008, Justin Perkins <justinperk...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Take the advice of kangax and Richard, > > > To set the selected item of a select box, you useselectedIndex. > > > There is no better way. Setting the selected attribute on an option is > > not a reliable means of setting the selected stateI will believe that statement if you post a test case that shows it to be unreliable.> >, not to mention it > > requires you to "unset" the selected attribute on another option.In a single select, setting the selected property of any particular option to true will set the selected property of all other option elements in the select to false. To set any particular option to selected, you simply set it''s selected property to true. That will also set the selectedIndex property of the select element. Setting the selected property in a multiple select does not change the value of the selected property of any other option. The selectedIndex property of the select element is set to the lowest index of all the selected options, so changing the selected property of individual select elements may or may not change the value of the selectedIndex property.> Just adding a few notes to this questio (not directly in response to > Justin''s recommendation). > > There are effectively 2 type of select boxes. > > select-multiple and select-single > > They behave slightly different with regard to the "select" properties. > > If select-single is used, then $(''select'').selectedIndexis the property to use.That opinion seems to be based on the erroneous belief that the selected property of every other option must be set to false, which is not true.> If select-multiple is used, then you $(''option_x'').selected is the > property to use.If the intention is to set more than one option to selected, then the selected property is the *only* reasonable way to do it[1]. Setting the select''s selectedIndex property will only ever select one option. If the intention is to select no options, then either set the select''s selectedIndex to -1 or loop over all the option elements and set their selected property to false. [...]> Setting option.selected is perfectly fine if your select is <select > multiple><opti....></select>The "best" way to set an option to selected is based on what the OP is actually trying to do, not necessarily on the type of select element. If the intention is to set a single option to selected in a multiple select, then selectedIndex is the best method. If the intention is to set any particular option to selected in a single select, then setting the selectedIndex property of the select OR setting the selected property of the particular option will do exactly the same thing. 1. An alert could be used to ask the user to do it themselves, or the innerHTML property of the select element could be modified to set the selected attribute of particular option elements. But I don''t consider those reasonable. -- Rob --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Well. You shouldn''t believe everything you read in the manual! Here is a simple script which does the basic setting or toggling of the selectedIndex/selected properties. Same result in both IE (7 WinXP SP2) and FF (2.0.0.11 WinXP SP2). It seems it makes no difference which you use to select the selected option(s), both work. I would like to know if this is true for all browsers/platforms. The script is at http://pastie.caboo.se/148590 Thanks RobG for questioning our initial comments. Richard. On 07/02/2008, RobG <rgqld-AFFH1GffN5hPR4JQBCEnsQ@public.gmane.org> wrote:> > On Jan 28, 9:59 pm, "Richard Quadling" <rquadl...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> > wrote: > > On 25/01/2008, Justin Perkins <justinperk...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Take the advice of kangax and Richard, > > > > > To set the selected item of a select box, you useselectedIndex. > > > > > There is no better way. Setting the selected attribute on an option is > > > not a reliable means of setting the selected state > > I will believe that statement if you post a test case that shows it to > be unreliable. > > > > >, not to mention it > > > requires you to "unset" the selected attribute on another option. > > In a single select, setting the selected property of any particular > option to true will set the selected property of all other option > elements in the select to false. To set any particular option to > selected, you simply set it''s selected property to true. That will > also set the selectedIndex property of the select element. > > Setting the selected property in a multiple select does not change the > value of the selected property of any other option. The selectedIndex > property of the select element is set to the lowest index of all the > selected options, so changing the selected property of individual > select elements may or may not change the value of the selectedIndex > property. > > > > Just adding a few notes to this questio (not directly in response to > > Justin''s recommendation). > > > > There are effectively 2 type of select boxes. > > > > select-multiple and select-single > > > > They behave slightly different with regard to the "select" properties. > > > > If select-single is used, then $(''select'').selectedIndexis the property to use. > > That opinion seems to be based on the erroneous belief that the > selected property of every other option must be set to false, which is > not true. > > > > > If select-multiple is used, then you $(''option_x'').selected is the > > property to use. > > If the intention is to set more than one option to selected, then the > selected property is the *only* reasonable way to do it[1]. Setting > the select''s selectedIndex property will only ever select one option. > > If the intention is to select no options, then either set the select''s > selectedIndex to -1 or loop over all the option elements and set their > selected property to false. > > > [...] > > > Setting option.selected is perfectly fine if your select is <select > > multiple><opti....></select> > > The "best" way to set an option to selected is based on what the OP is > actually trying to do, not necessarily on the type of select element. > If the intention is to set a single option to selected in a multiple > select, then selectedIndex is the best method. > > If the intention is to set any particular option to selected in a > single select, then setting the selectedIndex property of the select > OR setting the selected property of the particular option will do > exactly the same thing. > > > > 1. An alert could be used to ask the user to do it themselves, or the > innerHTML property of the select element could be modified to set the > selected attribute of particular option elements. But I don''t > consider those reasonable. > > > -- > Rob > > >-- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---