473,396 Members | 2,068 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,396 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 2003
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.