J
Jonathan
Hi everyone,
I have a problem with a HtmlSelect control that I am loading dynamically
in javascript. Here is my code:
<aspropDownList id="MyDropDownList1" onChange="LoadContent(this);"
runat="server">
<asp:ListItem value="0"> </asp:ListItem>
<asp:ListItem value="1">MyChoice1</asp:ListItem>
<asp:ListItem value="2">MyChoice2</asp:ListItem>
</aspropDownList>
<select id="MyList2" runat="server">
<option></option>
</select>
<asp:imageButton id="Save" imageURL="./Images/Save.gif"
onclick="Save_click" runat="server" />
<script language="javascript">
function LoadContent(elem)
{
if(elem.options[elem.selectedIndex].value==1)
{
var optionText = "MyText1";
var optionValue = 0;
var optionObject = new Option(optionText,optionValue);
optionRank = document.Myform.MyList2.options.length;
document.Myform.MyList2.options[optionRank]=optionObject;
optionText = "MyText2";
optionValue = 1;
optionObject = new Option(optionText,optionValue);
optionRank = document.Myform.MyList2.options.length;
document.Myform.MyList2.options[optionRank]=optionObject;
}
if(elem.options[elem.selectedIndex].value==2)
{
var optionText = "SomeText1";
var optionValue = 0;
var optionObject = new Option(optionText,optionValue);
optionRank = document.Myform.MyList2.options.length;
document.Myform.MyList2.options[optionRank]=optionObject;
optionText = "SomeText2";
optionValue = 1;
optionObject = new Option(optionText,optionValue);
optionRank = document.Myform.MyList2.options.length;
document.Myform.MyList2.options[optionRank]=optionObject;
}
}
</script>
<script language="vb" runat="server">
Sub Save_click( ByVal Sender as Object, ByVal As
ImageClickEventArgs )
//Get my value from MyList2 here
End Sub
</script>
Basically, my javascript function loads MyList2 (HtmlSelect control)
depending on what choice I made in my MyDropDownList1. I want to get the
value I selected in MyList2 when clicking on my Save ImageButton but i
don't know how to. I tried MyList2.Value but it is empty or i tried
MyList2.selectedIndex and it returns me 0. What am I doing wrong?
Any helps is greatly appreciated!
Jonathan
I have a problem with a HtmlSelect control that I am loading dynamically
in javascript. Here is my code:
<aspropDownList id="MyDropDownList1" onChange="LoadContent(this);"
runat="server">
<asp:ListItem value="0"> </asp:ListItem>
<asp:ListItem value="1">MyChoice1</asp:ListItem>
<asp:ListItem value="2">MyChoice2</asp:ListItem>
</aspropDownList>
<select id="MyList2" runat="server">
<option></option>
</select>
<asp:imageButton id="Save" imageURL="./Images/Save.gif"
onclick="Save_click" runat="server" />
<script language="javascript">
function LoadContent(elem)
{
if(elem.options[elem.selectedIndex].value==1)
{
var optionText = "MyText1";
var optionValue = 0;
var optionObject = new Option(optionText,optionValue);
optionRank = document.Myform.MyList2.options.length;
document.Myform.MyList2.options[optionRank]=optionObject;
optionText = "MyText2";
optionValue = 1;
optionObject = new Option(optionText,optionValue);
optionRank = document.Myform.MyList2.options.length;
document.Myform.MyList2.options[optionRank]=optionObject;
}
if(elem.options[elem.selectedIndex].value==2)
{
var optionText = "SomeText1";
var optionValue = 0;
var optionObject = new Option(optionText,optionValue);
optionRank = document.Myform.MyList2.options.length;
document.Myform.MyList2.options[optionRank]=optionObject;
optionText = "SomeText2";
optionValue = 1;
optionObject = new Option(optionText,optionValue);
optionRank = document.Myform.MyList2.options.length;
document.Myform.MyList2.options[optionRank]=optionObject;
}
}
</script>
<script language="vb" runat="server">
Sub Save_click( ByVal Sender as Object, ByVal As
ImageClickEventArgs )
//Get my value from MyList2 here
End Sub
</script>
Basically, my javascript function loads MyList2 (HtmlSelect control)
depending on what choice I made in my MyDropDownList1. I want to get the
value I selected in MyList2 when clicking on my Save ImageButton but i
don't know how to. I tried MyList2.Value but it is empty or i tried
MyList2.selectedIndex and it returns me 0. What am I doing wrong?
Any helps is greatly appreciated!
Jonathan