473,320 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

HtmlSelect control

Hi everyone,
I have a problem with a HtmlSelect control that I am loading dynamically
in javascript. Here is my code:

<asp:DropDownList id="MyDropDownList1" onChange="LoadContent(this);"
runat="server">
<asp:ListItem value="0">&nbsp;</asp:ListItem>
<asp:ListItem value="1">MyChoice1</asp:ListItem>
<asp:ListItem value="2">MyChoice2</asp:ListItem>
</asp:DropDownList>

<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

Nov 22 '05 #1
1 1996
Jonathan <aa*@aaa.com> wrote in
news:Xn***********************@206.167.113.5:
Hi everyone,
I have a problem with a HtmlSelect control that I am loading
dynamically in javascript. Here is my code:

<asp:DropDownList id="MyDropDownList1" onChange="LoadContent(this);"
runat="server">
<asp:ListItem value="0">&nbsp;</asp:ListItem>
<asp:ListItem value="1">MyChoice1</asp:ListItem>
<asp:ListItem value="2">MyChoice2</asp:ListItem>
</asp:DropDownList>

<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


It's ok, i found it.
For those interested, here is what i did:

1- i change my HtmlSelect control to classic html (no more runat=server)
<select name="MyList2">
<option></option>
</select>

2-on the Save_Click (after post to the server), i get my value by doing
a classic request

request.form("MyList2")
Jonathan

Nov 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jonathan | last post by:
Hi everyone, I have a problem with a HtmlSelect control that I am loading dynamically in javascript. Here is my code: <asp:DropDownList id="MyDropDownList1" onChange="LoadContent(this);"...
6
by: BK | last post by:
I'm having a really strange problem with and HtmlSelect server control (listbox) and a RequiredFieldValidator that I am trying to use to make sure that someone has items in the listbox. The way...
0
by: hash | last post by:
Hello, I have an <asp:table> control and inside this i am dynamically adding dropdownlists depending on values in the database. Whenever i try to bind any data to the HtmlSelect controls they...
1
by: Suhail A, Salman | last post by:
Dear All, I placed a HtmlSelect control on a web page and set it to "Run at Server", the objective of this HtmlSelect control is that the client adds all his accounts to a text box, and...
4
by: nospam | last post by:
HtmlSelect has a method called OnServerChange that supposed to detect whether the control (select) has changed on a postback. This is not all that useful. It should be like the asp.net...
2
by: Stephen Miller | last post by:
When I dynamically populate a HtmlSelect combo box, the Value property consistently fails to return the item selected, defaulting instead to the first item in the list. For example: Protected...
3
by: Joe | last post by:
Hello All, I am populating an HtmlSelect control's Items property with four list items. The HtmlSelect control is contained in a user control which is dropped into a placeholder on the web form....
1
by: writebrent | last post by:
This is my code: HtmlSelect m = new HtmlSelect(); m.ID = "m1"; m.DataSource = dvBasic; //DataView created elsewhere m.DataTextField = "value"; m.DataValueField = "key"; m.Value = "2";...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.