f



builder.node('select'..) selected not working solution

FYI,

with something like this:

hotelement = "hotelement"+hotcount;

	hotspot = Builder.node('div', { id:'hotspot'+hotcount,
className:'hotspot', style:''+divstyle }, [
				Builder.node('select', {id:hotelement, onChange:hotspotlink}, [
			        Builder.node('option',{value:'textfield',
selected:''},"textfield"),
			        Builder.node('option',{value:'textarea'},"textarea"),
					Builder.node('option',{value:'dropdown'},"dropdown"),
					Builder.node('option',{value:'checkbox'},"checkbox"),
					Builder.node('option',{value:'number'},"number"),
					Builder.node('option',{value:'date'},"date"),
					Builder.node('option',{value:'time'},"time")
				])
			]);

	$('column_container').appendChild( hotspot );

	$(hotelement).selectedIndex = 1;

the 

$(hotelement).selectedIndex = 1;

fixes the problem

0
sicapitan (19)
8/23/2006 1:26:34 PM
comp.lang.javascript 38370 articles. 2 followers. javascript4 (1315) is leader. Post Follow

2 Replies
528 Views

Similar Articles

[PageSpeed] 37

sicapitan wrote:
<snip>
>    Builder.node('option',{value:'textfield', selected:''},"textfield"),

Because you are not including the code for the objects/method/functions
being used here it is impossible to tell what these 'parameters' are
intended for, but it seems likely that whether - selected - is destined
to be an element property or an attribute (unlikely given the poor
support on IE) the value of an empty string would be a useful value to
be using. If the intention is to set a - selected - property of the
element then because the empty string type-converts to boolean false
when assigned to a boolean element value the result would be an option
that was _not_ selected, and the only value for a selected attribute is
the string "selected".

<snip>
>   $(hotelement).selectedIndex = 1;
>
> the
>
> $(hotelement).selectedIndex = 1;
>
> fixes the problem

What problem? Not by any chance the problem that you expect the second
option to be selected and that is not the case without the explicit
assignment to the selectedIndex?

Richard.

0
Richard
8/23/2006 2:04:53 PM
i made a mistake, selected:'selected'

its a bug in FF apparently, mentioned elsewhere, setting the index
fixes it

problem was no option was selected, and it would jump to the last, as
the builder code would write selected='selected' with no defaults to a
blank value.

cheers
r

Richard Cornford wrote:
> sicapitan wrote:
> <snip>
> >    Builder.node('option',{value:'textfield', selected:''},"textfield"),
>
> Because you are not including the code for the objects/method/functions
> being used here it is impossible to tell what these 'parameters' are
> intended for, but it seems likely that whether - selected - is destined
> to be an element property or an attribute (unlikely given the poor
> support on IE) the value of an empty string would be a useful value to
> be using. If the intention is to set a - selected - property of the
> element then because the empty string type-converts to boolean false
> when assigned to a boolean element value the result would be an option
> that was _not_ selected, and the only value for a selected attribute is
> the string "selected".
>
> <snip>
> >   $(hotelement).selectedIndex = 1;
> >
> > the
> >
> > $(hotelement).selectedIndex = 1;
> >
> > fixes the problem
>
> What problem? Not by any chance the problem that you expect the second
> option to be selected and that is not the case without the explicit
> assignment to the selectedIndex?
> 
> Richard.

0
sicapitan
8/23/2006 2:19:47 PM
Reply: