How to add items to a dropdownlist control within a Javascript eventhandler?

O

Oscar

I want to add items to a dropdownlist control within a Javascript
eventhandler.
This is what I code :

var dd = document.getElementById("DropDownList1");

dd.Items.Add("1990");
dd.Items.Add("1991");
dd.Items.Add("1992");

however, it doesn't work.

What should I code instead ?
 
D

Daniel Walzenbach

Oscar,

try the following:

document.getElementById("DropDownList").options[0] = new Option("1990",
"1990");

Regards
 
O

Oscar

Daniel,
thanks for the advice. This solution works in case the DropDownList is
positioned free within a page.
However, In my case it is part of a Webgrid, as part of the NetAdvantage Web
Controls and within this configuration, it doesn't work.
I've attached a part of the HTML. Maybe you can find the origin of the
problem.

regards,
Oscar

<igtbl:ultrawebgrid id="UltraWebGrid1" style="Z-INDEX: 101; LEFT: 104px;
POSITION: absolute; TOP: 48px"
runat="server" Height="200px" Width="325px">
<DisplayLayout RowHeightDefault="20px" Version="4.00"
BorderCollapseDefault="Separate" Name="UltraWebGrid1">
<AddNewBox>
<Style BorderWidth="1px" BorderStyle="Solid" BackColor="LightGray">

<BorderDetails ColorTop="White" WidthLeft="1px" WidthTop="1px"
ColorLeft="White">
</BorderDetails>

</Style>
</AddNewBox>
<Pager>
<Style BorderWidth="1px" BorderStyle="Solid" BackColor="LightGray">

<BorderDetails ColorTop="White" WidthLeft="1px" WidthTop="1px"
ColorLeft="White">
</BorderDetails>

</Style>
</Pager>
<HeaderStyleDefault BorderStyle="Solid" BackColor="LightGray">
<BorderDetails ColorTop="White" WidthLeft="1px" WidthTop="1px"
ColorLeft="White"></BorderDetails>
</HeaderStyleDefault>
<FrameStyle Width="325px" BorderWidth="1px" Font-Size="8pt"
Font-Names="Verdana" BorderStyle="Solid"
Height="200px"></FrameStyle>
<FooterStyleDefault BorderWidth="1px" BorderStyle="Solid"
BackColor="LightGray">
<BorderDetails ColorTop="White" WidthLeft="1px" WidthTop="1px"
ColorLeft="White"></BorderDetails>
</FooterStyleDefault>
<ClientSideEvents
BeforeRowTemplateOpenHandler="UltraWebGrid1_BeforeRowTemplateOpenHandler"
AfterRowTemplateOpenHandler="UltraWebGrid1_AfterRowTemplateOpenHandler"></ClientSideEvents>
<EditCellStyleDefault BorderWidth="0px"
BorderStyle="None"></EditCellStyleDefault>
<RowStyleDefault BorderWidth="1px" BorderColor="Gray"
BorderStyle="Solid">
<Padding Left="3px"></Padding>
<BorderDetails WidthLeft="0px" WidthTop="0px"></BorderDetails>
</RowStyleDefault>
</DisplayLayout>
<Bands>
<igtbl:UltraGridBand AllowUpdate="RowTemplateOnly" AllowAdd="Yes">
<Columns>
<igtbl:UltraGridColumn HeaderText="naam" Key="naam"
BaseColumnName="">
<Footer Key="naam"></Footer>
<Header Key="naam" Caption="naam"></Header>
</igtbl:UltraGridColumn>
<igtbl:UltraGridColumn HeaderText="kleur" Key="kleur"
Type="DropDownList" BaseColumnName="">
<ValueList>
<ValueListItems>
<igtbl:ValueListItem DataValue="geel" Key="geel"
DisplayText="geel"></igtbl:ValueListItem>
<igtbl:ValueListItem DataValue="rood" Key="rood"
DisplayText="rood"></igtbl:ValueListItem>
<igtbl:ValueListItem DataValue="blauw" Key="blauw"
DisplayText="blauw"></igtbl:ValueListItem>
</ValueListItems>
</ValueList>
<Footer Key="kleur"></Footer>
<Header Key="kleur" Caption="kleur"></Header>
</igtbl:UltraGridColumn>
</Columns>
<RowEditTemplate>
<DIV style="WIDTH: 256px; POSITION: relative; HEIGHT: 104px"
ms_positioning="GridLayout">
<asp:Label id="Label1" style="Z-INDEX: 101; LEFT: 16px; POSITION:
absolute; TOP: 16px" runat="server">naam</asp:Label>
<asp:Label id="Label2" style="Z-INDEX: 102; LEFT: 16px; POSITION:
absolute; TOP: 56px" runat="server">kleur</asp:Label>
<asp:TextBox id="TextBox1" style="Z-INDEX: 103; LEFT: 72px;
POSITION: absolute; TOP: 16px" runat="server"
columnKey="naam"></asp:TextBox>
<asp:DropDownList id="DropDownList1" style="Z-INDEX: 104; LEFT:
72px; POSITION: absolute; TOP: 56px"
runat="server" Width="160px"
columnKey="kleur"></asp:DropDownList></DIV>
<BR>
<P align="center"><INPUT id="igtbl_reOkBtn" style="WIDTH: 50px"
onclick="igtbl_gRowEditButtonClick(event);"
type="button" value="OK">&nbsp; <INPUT id="igtbl_reCancelBtn"
style="WIDTH: 50px" onclick="igtbl_gRowEditButtonClick(event);"
type="button" value="Cancel"></P>
</RowEditTemplate>
<RowTemplateStyle BorderColor="White" BorderStyle="Ridge"
BackColor="White">
<BorderDetails WidthLeft="3px" WidthTop="3px" WidthRight="3px"
WidthBottom="3px"></BorderDetails>
</RowTemplateStyle>
</igtbl:UltraGridBand>
</Bands>
</igtbl:ultrawebgrid>




Daniel Walzenbach said:
Oscar,

try the following:

document.getElementById("DropDownList").options[0] = new Option("1990",
"1990");

Regards

---------------------------------------
Daniel Walzenbach
MCP

www.walzenbach.net



Oscar said:
I want to add items to a dropdownlist control within a Javascript
eventhandler.
This is what I code :

var dd = document.getElementById("DropDownList1");

dd.Items.Add("1990");
dd.Items.Add("1991");
dd.Items.Add("1992");

however, it doesn't work.

What should I code instead ?
 
D

Daniel Walzenbach

Oscar,

did you check what will be rendered on your page. Do a "View Source" of the
page and check out the naming pattern.

Does this help?

---------------------------------------
Daniel Walzenbach
MCP

www.walzenbach.net



Oscar said:
Daniel,
thanks for the advice. This solution works in case the DropDownList is
positioned free within a page.
However, In my case it is part of a Webgrid, as part of the NetAdvantage
Web Controls and within this configuration, it doesn't work.
I've attached a part of the HTML. Maybe you can find the origin of the
problem.

regards,
Oscar

<igtbl:ultrawebgrid id="UltraWebGrid1" style="Z-INDEX: 101; LEFT: 104px;
POSITION: absolute; TOP: 48px"
runat="server" Height="200px" Width="325px">
<DisplayLayout RowHeightDefault="20px" Version="4.00"
BorderCollapseDefault="Separate" Name="UltraWebGrid1">
<AddNewBox>
<Style BorderWidth="1px" BorderStyle="Solid" BackColor="LightGray">

<BorderDetails ColorTop="White" WidthLeft="1px" WidthTop="1px"
ColorLeft="White">
</BorderDetails>

</Style>
</AddNewBox>
<Pager>
<Style BorderWidth="1px" BorderStyle="Solid" BackColor="LightGray">

<BorderDetails ColorTop="White" WidthLeft="1px" WidthTop="1px"
ColorLeft="White">
</BorderDetails>

</Style>
</Pager>
<HeaderStyleDefault BorderStyle="Solid" BackColor="LightGray">
<BorderDetails ColorTop="White" WidthLeft="1px" WidthTop="1px"
ColorLeft="White"></BorderDetails>
</HeaderStyleDefault>
<FrameStyle Width="325px" BorderWidth="1px" Font-Size="8pt"
Font-Names="Verdana" BorderStyle="Solid"
Height="200px"></FrameStyle>
<FooterStyleDefault BorderWidth="1px" BorderStyle="Solid"
BackColor="LightGray">
<BorderDetails ColorTop="White" WidthLeft="1px" WidthTop="1px"
ColorLeft="White"></BorderDetails>
</FooterStyleDefault>
<ClientSideEvents
BeforeRowTemplateOpenHandler="UltraWebGrid1_BeforeRowTemplateOpenHandler"
AfterRowTemplateOpenHandler="UltraWebGrid1_AfterRowTemplateOpenHandler"></ClientSideEvents>
<EditCellStyleDefault BorderWidth="0px"
BorderStyle="None"></EditCellStyleDefault>
<RowStyleDefault BorderWidth="1px" BorderColor="Gray"
BorderStyle="Solid">
<Padding Left="3px"></Padding>
<BorderDetails WidthLeft="0px" WidthTop="0px"></BorderDetails>
</RowStyleDefault>
</DisplayLayout>
<Bands>
<igtbl:UltraGridBand AllowUpdate="RowTemplateOnly" AllowAdd="Yes">
<Columns>
<igtbl:UltraGridColumn HeaderText="naam" Key="naam"
BaseColumnName="">
<Footer Key="naam"></Footer>
<Header Key="naam" Caption="naam"></Header>
</igtbl:UltraGridColumn>
<igtbl:UltraGridColumn HeaderText="kleur" Key="kleur"
Type="DropDownList" BaseColumnName="">
<ValueList>
<ValueListItems>
<igtbl:ValueListItem DataValue="geel" Key="geel"
DisplayText="geel"></igtbl:ValueListItem>
<igtbl:ValueListItem DataValue="rood" Key="rood"
DisplayText="rood"></igtbl:ValueListItem>
<igtbl:ValueListItem DataValue="blauw" Key="blauw"
DisplayText="blauw"></igtbl:ValueListItem>
</ValueListItems>
</ValueList>
<Footer Key="kleur"></Footer>
<Header Key="kleur" Caption="kleur"></Header>
</igtbl:UltraGridColumn>
</Columns>
<RowEditTemplate>
<DIV style="WIDTH: 256px; POSITION: relative; HEIGHT: 104px"
ms_positioning="GridLayout">
<asp:Label id="Label1" style="Z-INDEX: 101; LEFT: 16px; POSITION:
absolute; TOP: 16px" runat="server">naam</asp:Label>
<asp:Label id="Label2" style="Z-INDEX: 102; LEFT: 16px; POSITION:
absolute; TOP: 56px" runat="server">kleur</asp:Label>
<asp:TextBox id="TextBox1" style="Z-INDEX: 103; LEFT: 72px;
POSITION: absolute; TOP: 16px" runat="server"
columnKey="naam"></asp:TextBox>
<asp:DropDownList id="DropDownList1" style="Z-INDEX: 104; LEFT:
72px; POSITION: absolute; TOP: 56px"
runat="server" Width="160px"
columnKey="kleur"></asp:DropDownList></DIV>
<BR>
<P align="center"><INPUT id="igtbl_reOkBtn" style="WIDTH: 50px"
onclick="igtbl_gRowEditButtonClick(event);"
type="button" value="OK">&nbsp; <INPUT id="igtbl_reCancelBtn"
style="WIDTH: 50px" onclick="igtbl_gRowEditButtonClick(event);"
type="button" value="Cancel"></P>
</RowEditTemplate>
<RowTemplateStyle BorderColor="White" BorderStyle="Ridge"
BackColor="White">
<BorderDetails WidthLeft="3px" WidthTop="3px" WidthRight="3px"
WidthBottom="3px"></BorderDetails>
</RowTemplateStyle>
</igtbl:UltraGridBand>
</Bands>
</igtbl:ultrawebgrid>




Daniel Walzenbach said:
Oscar,

try the following:

document.getElementById("DropDownList").options[0] = new Option("1990",
"1990");

Regards

---------------------------------------
Daniel Walzenbach
MCP

www.walzenbach.net



Oscar said:
I want to add items to a dropdownlist control within a Javascript
eventhandler.
This is what I code :

var dd = document.getElementById("DropDownList1");

dd.Items.Add("1990");
dd.Items.Add("1991");
dd.Items.Add("1992");

however, it doesn't work.

What should I code instead ?
 
O

Oscar

Daniel,

You are a hero to me! I've done the view source and I saw that the ID was
rewritten as ID= UltraWebGrid1__ctl0_DropDownList1. I've changed the HTML
source to

document.getElementById("UltraWebGrid1__ctl0_DropDownList1").options[0] =
new Option("1990", "1990");

and now it's working!

thank you very much and have a nice day.

regards,
Oscar


Daniel Walzenbach said:
Oscar,

did you check what will be rendered on your page. Do a "View Source" of
the page and check out the naming pattern.

Does this help?

---------------------------------------
Daniel Walzenbach
MCP

www.walzenbach.net



Oscar said:
Daniel,
thanks for the advice. This solution works in case the DropDownList is
positioned free within a page.
However, In my case it is part of a Webgrid, as part of the NetAdvantage
Web Controls and within this configuration, it doesn't work.
I've attached a part of the HTML. Maybe you can find the origin of the
problem.

regards,
Oscar

<igtbl:ultrawebgrid id="UltraWebGrid1" style="Z-INDEX: 101; LEFT: 104px;
POSITION: absolute; TOP: 48px"
runat="server" Height="200px" Width="325px">
<DisplayLayout RowHeightDefault="20px" Version="4.00"
BorderCollapseDefault="Separate" Name="UltraWebGrid1">
<AddNewBox>
<Style BorderWidth="1px" BorderStyle="Solid" BackColor="LightGray">

<BorderDetails ColorTop="White" WidthLeft="1px" WidthTop="1px"
ColorLeft="White">
</BorderDetails>

</Style>
</AddNewBox>
<Pager>
<Style BorderWidth="1px" BorderStyle="Solid" BackColor="LightGray">

<BorderDetails ColorTop="White" WidthLeft="1px" WidthTop="1px"
ColorLeft="White">
</BorderDetails>

</Style>
</Pager>
<HeaderStyleDefault BorderStyle="Solid" BackColor="LightGray">
<BorderDetails ColorTop="White" WidthLeft="1px" WidthTop="1px"
ColorLeft="White"></BorderDetails>
</HeaderStyleDefault>
<FrameStyle Width="325px" BorderWidth="1px" Font-Size="8pt"
Font-Names="Verdana" BorderStyle="Solid"
Height="200px"></FrameStyle>
<FooterStyleDefault BorderWidth="1px" BorderStyle="Solid"
BackColor="LightGray">
<BorderDetails ColorTop="White" WidthLeft="1px" WidthTop="1px"
ColorLeft="White"></BorderDetails>
</FooterStyleDefault>
<ClientSideEvents
BeforeRowTemplateOpenHandler="UltraWebGrid1_BeforeRowTemplateOpenHandler"
AfterRowTemplateOpenHandler="UltraWebGrid1_AfterRowTemplateOpenHandler"></ClientSideEvents>
<EditCellStyleDefault BorderWidth="0px"
BorderStyle="None"></EditCellStyleDefault>
<RowStyleDefault BorderWidth="1px" BorderColor="Gray"
BorderStyle="Solid">
<Padding Left="3px"></Padding>
<BorderDetails WidthLeft="0px" WidthTop="0px"></BorderDetails>
</RowStyleDefault>
</DisplayLayout>
<Bands>
<igtbl:UltraGridBand AllowUpdate="RowTemplateOnly" AllowAdd="Yes">
<Columns>
<igtbl:UltraGridColumn HeaderText="naam" Key="naam"
BaseColumnName="">
<Footer Key="naam"></Footer>
<Header Key="naam" Caption="naam"></Header>
</igtbl:UltraGridColumn>
<igtbl:UltraGridColumn HeaderText="kleur" Key="kleur"
Type="DropDownList" BaseColumnName="">
<ValueList>
<ValueListItems>
<igtbl:ValueListItem DataValue="geel" Key="geel"
DisplayText="geel"></igtbl:ValueListItem>
<igtbl:ValueListItem DataValue="rood" Key="rood"
DisplayText="rood"></igtbl:ValueListItem>
<igtbl:ValueListItem DataValue="blauw" Key="blauw"
DisplayText="blauw"></igtbl:ValueListItem>
</ValueListItems>
</ValueList>
<Footer Key="kleur"></Footer>
<Header Key="kleur" Caption="kleur"></Header>
</igtbl:UltraGridColumn>
</Columns>
<RowEditTemplate>
<DIV style="WIDTH: 256px; POSITION: relative; HEIGHT: 104px"
ms_positioning="GridLayout">
<asp:Label id="Label1" style="Z-INDEX: 101; LEFT: 16px; POSITION:
absolute; TOP: 16px" runat="server">naam</asp:Label>
<asp:Label id="Label2" style="Z-INDEX: 102; LEFT: 16px; POSITION:
absolute; TOP: 56px" runat="server">kleur</asp:Label>
<asp:TextBox id="TextBox1" style="Z-INDEX: 103; LEFT: 72px;
POSITION: absolute; TOP: 16px" runat="server"
columnKey="naam"></asp:TextBox>
<asp:DropDownList id="DropDownList1" style="Z-INDEX: 104; LEFT:
72px; POSITION: absolute; TOP: 56px"
runat="server" Width="160px"
columnKey="kleur"></asp:DropDownList></DIV>
<BR>
<P align="center"><INPUT id="igtbl_reOkBtn" style="WIDTH: 50px"
onclick="igtbl_gRowEditButtonClick(event);"
type="button" value="OK">&nbsp; <INPUT id="igtbl_reCancelBtn"
style="WIDTH: 50px" onclick="igtbl_gRowEditButtonClick(event);"
type="button" value="Cancel"></P>
</RowEditTemplate>
<RowTemplateStyle BorderColor="White" BorderStyle="Ridge"
BackColor="White">
<BorderDetails WidthLeft="3px" WidthTop="3px" WidthRight="3px"
WidthBottom="3px"></BorderDetails>
</RowTemplateStyle>
</igtbl:UltraGridBand>
</Bands>
</igtbl:ultrawebgrid>




Daniel Walzenbach said:
Oscar,

try the following:

document.getElementById("DropDownList").options[0] = new Option("1990",
"1990");

Regards

---------------------------------------
Daniel Walzenbach
MCP

www.walzenbach.net



I want to add items to a dropdownlist control within a Javascript
eventhandler.
This is what I code :

var dd = document.getElementById("DropDownList1");

dd.Items.Add("1990");
dd.Items.Add("1991");
dd.Items.Add("1992");

however, it doesn't work.

What should I code instead ?
 
D

Daniel Walzenbach

Thanks Oscar,



Glad I could help! What you see is basically what happens. To guarantee
uniqueness all "repeater"-controls translate the ID to a progressional. ID.
Actually the tip I gave you is helpful in a lot of scenarios. Especially if
you want to know how webcontrols are "translated".



Take care


---------------------------------------
Daniel Walzenbach
MCP

www.walzenbach.net



Oscar said:
Daniel,

You are a hero to me! I've done the view source and I saw that the ID was
rewritten as ID= UltraWebGrid1__ctl0_DropDownList1. I've changed the HTML
source to

document.getElementById("UltraWebGrid1__ctl0_DropDownList1").options[0] =
new Option("1990", "1990");

and now it's working!

thank you very much and have a nice day.

regards,
Oscar


Daniel Walzenbach said:
Oscar,

did you check what will be rendered on your page. Do a "View Source" of
the page and check out the naming pattern.

Does this help?

---------------------------------------
Daniel Walzenbach
MCP

www.walzenbach.net



Oscar said:
Daniel,
thanks for the advice. This solution works in case the DropDownList is
positioned free within a page.
However, In my case it is part of a Webgrid, as part of the NetAdvantage
Web Controls and within this configuration, it doesn't work.
I've attached a part of the HTML. Maybe you can find the origin of the
problem.

regards,
Oscar

<igtbl:ultrawebgrid id="UltraWebGrid1" style="Z-INDEX: 101; LEFT: 104px;
POSITION: absolute; TOP: 48px"
runat="server" Height="200px" Width="325px">
<DisplayLayout RowHeightDefault="20px" Version="4.00"
BorderCollapseDefault="Separate" Name="UltraWebGrid1">
<AddNewBox>
<Style BorderWidth="1px" BorderStyle="Solid" BackColor="LightGray">

<BorderDetails ColorTop="White" WidthLeft="1px" WidthTop="1px"
ColorLeft="White">
</BorderDetails>

</Style>
</AddNewBox>
<Pager>
<Style BorderWidth="1px" BorderStyle="Solid" BackColor="LightGray">

<BorderDetails ColorTop="White" WidthLeft="1px" WidthTop="1px"
ColorLeft="White">
</BorderDetails>

</Style>
</Pager>
<HeaderStyleDefault BorderStyle="Solid" BackColor="LightGray">
<BorderDetails ColorTop="White" WidthLeft="1px" WidthTop="1px"
ColorLeft="White"></BorderDetails>
</HeaderStyleDefault>
<FrameStyle Width="325px" BorderWidth="1px" Font-Size="8pt"
Font-Names="Verdana" BorderStyle="Solid"
Height="200px"></FrameStyle>
<FooterStyleDefault BorderWidth="1px" BorderStyle="Solid"
BackColor="LightGray">
<BorderDetails ColorTop="White" WidthLeft="1px" WidthTop="1px"
ColorLeft="White"></BorderDetails>
</FooterStyleDefault>
<ClientSideEvents
BeforeRowTemplateOpenHandler="UltraWebGrid1_BeforeRowTemplateOpenHandler"
AfterRowTemplateOpenHandler="UltraWebGrid1_AfterRowTemplateOpenHandler"></ClientSideEvents>
<EditCellStyleDefault BorderWidth="0px"
BorderStyle="None"></EditCellStyleDefault>
<RowStyleDefault BorderWidth="1px" BorderColor="Gray"
BorderStyle="Solid">
<Padding Left="3px"></Padding>
<BorderDetails WidthLeft="0px" WidthTop="0px"></BorderDetails>
</RowStyleDefault>
</DisplayLayout>
<Bands>
<igtbl:UltraGridBand AllowUpdate="RowTemplateOnly" AllowAdd="Yes">
<Columns>
<igtbl:UltraGridColumn HeaderText="naam" Key="naam"
BaseColumnName="">
<Footer Key="naam"></Footer>
<Header Key="naam" Caption="naam"></Header>
</igtbl:UltraGridColumn>
<igtbl:UltraGridColumn HeaderText="kleur" Key="kleur"
Type="DropDownList" BaseColumnName="">
<ValueList>
<ValueListItems>
<igtbl:ValueListItem DataValue="geel" Key="geel"
DisplayText="geel"></igtbl:ValueListItem>
<igtbl:ValueListItem DataValue="rood" Key="rood"
DisplayText="rood"></igtbl:ValueListItem>
<igtbl:ValueListItem DataValue="blauw" Key="blauw"
DisplayText="blauw"></igtbl:ValueListItem>
</ValueListItems>
</ValueList>
<Footer Key="kleur"></Footer>
<Header Key="kleur" Caption="kleur"></Header>
</igtbl:UltraGridColumn>
</Columns>
<RowEditTemplate>
<DIV style="WIDTH: 256px; POSITION: relative; HEIGHT: 104px"
ms_positioning="GridLayout">
<asp:Label id="Label1" style="Z-INDEX: 101; LEFT: 16px; POSITION:
absolute; TOP: 16px" runat="server">naam</asp:Label>
<asp:Label id="Label2" style="Z-INDEX: 102; LEFT: 16px; POSITION:
absolute; TOP: 56px" runat="server">kleur</asp:Label>
<asp:TextBox id="TextBox1" style="Z-INDEX: 103; LEFT: 72px;
POSITION: absolute; TOP: 16px" runat="server"
columnKey="naam"></asp:TextBox>
<asp:DropDownList id="DropDownList1" style="Z-INDEX: 104; LEFT:
72px; POSITION: absolute; TOP: 56px"
runat="server" Width="160px"
columnKey="kleur"></asp:DropDownList></DIV>
<BR>
<P align="center"><INPUT id="igtbl_reOkBtn" style="WIDTH: 50px"
onclick="igtbl_gRowEditButtonClick(event);"
type="button" value="OK">&nbsp; <INPUT id="igtbl_reCancelBtn"
style="WIDTH: 50px" onclick="igtbl_gRowEditButtonClick(event);"
type="button" value="Cancel"></P>
</RowEditTemplate>
<RowTemplateStyle BorderColor="White" BorderStyle="Ridge"
BackColor="White">
<BorderDetails WidthLeft="3px" WidthTop="3px" WidthRight="3px"
WidthBottom="3px"></BorderDetails>
</RowTemplateStyle>
</igtbl:UltraGridBand>
</Bands>
</igtbl:ultrawebgrid>




"Daniel Walzenbach" <[email protected]> schreef in
bericht Oscar,

try the following:

document.getElementById("DropDownList").options[0] = new Option("1990",
"1990");

Regards

---------------------------------------
Daniel Walzenbach
MCP

www.walzenbach.net



I want to add items to a dropdownlist control within a Javascript
eventhandler.
This is what I code :

var dd = document.getElementById("DropDownList1");

dd.Items.Add("1990");
dd.Items.Add("1991");
dd.Items.Add("1992");

however, it doesn't work.

What should I code instead ?
 
E

Eirik

How about using ClientID of the control, and writing out the script from
CodeBehind.
See here for an example:
http://aspnet.4guysfromrolla.com/articles/091703-1.2.aspx

Look for the section "Emitting the Client-Side JavaScript"

Regards

Oscar said:
Daniel,

You are a hero to me! I've done the view source and I saw that the ID was
rewritten as ID= UltraWebGrid1__ctl0_DropDownList1. I've changed the HTML
source to

document.getElementById("UltraWebGrid1__ctl0_DropDownList1").options[0] =
new Option("1990", "1990");

and now it's working!

thank you very much and have a nice day.

regards,
Oscar


Daniel Walzenbach said:
Oscar,

did you check what will be rendered on your page. Do a "View Source" of
the page and check out the naming pattern.

Does this help?

---------------------------------------
Daniel Walzenbach
MCP

www.walzenbach.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top