Hi,

`innerHTML` isn't an attribute, which is why you can't set it as part
of the `attributes` parameter to `new Element`.

The usual way to create an Option object is via the `Option`
constructor, which isn't Prototype-specific:

var o = new Option(text, value);

So since you're using the same text and value:

var o = new Option(times[i], times[i]);

It's supported by every browser I've ever met (but I've mostly worked
with major browsers, not niche ones). The resulting object isn't
(reliably cross-browser) an actual DOM element, but the option is
handled correctly if you add it to the select box's `options`
collection via its `add` method (yes, `add`, not `push` as you might
expect) or by assigning to the next available slot directly:

// using `add` (`push` does not work)
yourSelectBox.options.add(o);

// or assigning directly to next available slot:
yourSelectBox.options[yourSelectBox.options.length] = o;

Live example: http://jsbin.com/ujopa4

I believe that's the most compatible way to do it.

I tried doing a Prototype example with actual DOM elements:

var o = new Element('option', {value: times[i]});
o.update(times[i]);
yourSelectBox.insert(o);

(Live example: http://jsbin.com/usatu4) ...but on IE6 that worked in
that the elements were added to the drop-down, but the drop-down's
width wasn't recalculated.

HTH,
--
T.J. Crowder
Independent Software Engineer
tj / crowder software / com
www / crowder software / com

On Feb 3, 3:36 am, greg <g...@reservation-net.com> wrote:
> Hi folks,
>
> Is there a way using just new Element to create an Option element?
>
> To get it to work in FF and IE, I need to do the following:
>
> var o = new Element('Option', {'value': times[i], 'innerHTML':
> times[i]});  // for IE
> o.text = times[i];  // for FF
>
> This doesn't work in FF:
> var o = new Element('Option', {'value': times[i], 'text': times[i],
> 'innerHTML': times[i]});
>
> innerText doesn't work in FF either.
>
> Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to