I guess you could do something like this:

select.options[select.options.length] = new Option(text,value);


While it works, I still think the interface is poor. It is inconsistent with
any other DOM node. In addition using new Option limits what you can do with
an option node, it lacks the interface your use to with a typical html node.




On Mon, Aug 24, 2009 at 7:28 AM, nwhite <changereal...@gmail.com> wrote:

>
>
> On Mon, Aug 24, 2009 at 7:17 AM, Steve Onnis <st...@cfcentral.com.au>wrote:
>
>>  So if it doesnt mix then dont mix it and you dont have to mix it.  Why
>> would you mix it when it is as simple as
>>
>> new Option() ?
>>
>
>
> Have you tested it? Using 'new Option()' requires the use of select.add(
> new Option ) because appendChild breaks new Option in IE. As the article
> points out about .add() :
>
> The spec defines that the second parameter should be null instead of
> undefined in order to append to the end of the list. This means that in any
> browser that follows the spec the second parameter must be explicitly set.
> This is one rare example where I prefer IE’s implementation.
>
> // in FF or W3C compliant browser
> selectBox.add(new Option(text,value),null);
>
> Problem with this is IE does not understand the null and fails. so you have
> to wrap this in a try catch.
>
> try {
> selectBox.add(new Option(text,value),null);
> } catch(ex){
> selectBox.add(new Option(text,value));
> }
>
>
> @Steve nothing is wrong with new Option() in of itself. Its when you go to
> insert it into a select node. I donno about you but that try/catch looks
> ugly and I would rather avoid it if I could. Sticking with a pure DOM2
> interface is cleaner, and easier to debug.
>
>
>
>
>
>
>
>
>>
>>  ------------------------------
>> *From:* nwhite [mailto:changereal...@gmail.com]
>> *Sent:* Monday, 24 August 2009 9:56 PM
>>
>> *To:* mootools-users@googlegroups.com
>> *Subject:* [Moo] Re: Dynamic Dropdownlists
>>
>> new Option isn't "bad", it just ugly to deal with. My biggest issue is the
>> handling of the explicit 2 parameters for the add method. FF, Safari require
>> it. IE, fails when its present. This mean wrapping it in a a try/catch. Like
>> I said the older DOM api doesn't mix with the new one in IE. so appendChild(
>> new Option) fails.
>>
>> selectBox.appendChild( new Element('option', {'value' : value 
>> }).appendText(text) );
>>
>> solves all my issues.
>>
>>
>>
>> On Mon, Aug 24, 2009 at 4:21 AM, Thierry bela nanga <bna...@gmail.com>wrote:
>>
>>> I remember I had problem with utf-8 using the new Option in IE a very
>>> long time ago...
>>>
>>>
>>> On Mon, Aug 24, 2009 at 12:04 PM, Steve Onnis <st...@cfcentral.com.au>wrote:
>>>
>>>>  had a read of this....can you explain why *new Option()* is bad if it
>>>> is still supported?
>>>>
>>>> With all the other option you has to mess around with it to get it to
>>>> work.  *new Option()* just works and always has so i dont see it being
>>>> bad especially when you are dealing with older browsers
>>>>
>>>>  ------------------------------
>>>> *From:* nwhite [mailto:changereal...@gmail.com]
>>>> *Sent:* Monday, 24 August 2009 8:44 PM
>>>> *To:* mootools-users@googlegroups.com
>>>> *Subject:* [Moo] Re: Dynamic Dropdownlists
>>>>
>>>>   I wrote a post a while ago about the bugs/features surrounding
>>>> dynamic population of a select form.
>>>>
>>>>
>>>> http://www.propertymaps.com/blog/2008/04/10/dynamically-populating-select-elements-with-javascript/
>>>>
>>>>
>>>>
>>>> On Mon, Aug 24, 2009 at 3:23 AM, Steve Onnis <st...@cfcentral.com.au>wrote:
>>>>
>>>>>  selects are funny like that
>>>>>
>>>>> I would be using the JS to use *new Option()* to insert the options,
>>>>> not HTML like that.
>>>>>
>>>>>  ------------------------------
>>>>> *From:* Justin Meighan [mailto:jusm...@gmail.com]
>>>>> *Sent:* Monday, 24 August 2009 8:11 PM
>>>>> *To:* mootools-users@googlegroups.com
>>>>> *Subject:* [Moo] Dynamic Dropdownlists
>>>>>
>>>>>   Hi guys,
>>>>>
>>>>> I'm using mootools to create some dynamic dropdownlists.
>>>>> Basically the user selects from a list, and the second list is
>>>>> dynamically populated.
>>>>>
>>>>> The way I have been trying to do it is as follows:
>>>>>
>>>>> 1. Onchange on list one I did a Request.HTML to a script that game me
>>>>> back the option values for list 2. I then injected the options into the id
>>>>> of my second list.
>>>>>
>>>>> It kind of works, but for some reason the list ony seems to have 1 item
>>>>> in it, despite there being 4-5 properly formed <option
>>>>> value="">blah</option> tags?
>>>>>
>>>>> Any ideas why it lists them all as just one option?
>>>>>
>>>>> Thanx
>>>>>
>>>>> Justin
>>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> http://tbela99.blogspot.com/
>>>
>>> fax : (+33) 08 26 51 94 51
>>>
>>
>>
>

Reply via email to