473,626 Members | 3,291 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HtmlSelect control

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

<asp:DropDownLi st id="MyDropDownL ist1" onChange="LoadC ontent(this);"
runat="server">
<asp:ListItem value="0">&nbsp ;</asp:ListItem>
<asp:ListItem value="1">MyCho ice1</asp:ListItem>
<asp:ListItem value="2">MyCho ice2</asp:ListItem>
</asp:DropDownLis t>

<select id="MyList2" runat="server">
<option></option>
</select>

<asp:imageButto n id="Save" imageURL="./Images/Save.gif"
onclick="Save_c lick" runat="server" />

<script language="javas cript">
function LoadContent(ele m)
{
if(elem.options[elem.selectedIn dex].value==1)
{
var optionText = "MyText1";
var optionValue = 0;
var optionObject = new Option(optionTe xt,optionValue) ;
optionRank = document.Myform .MyList2.option s.length;
document.Myform .MyList2.option s[optionRank]=optionObject;
optionText = "MyText2";
optionValue = 1;
optionObject = new Option(optionTe xt,optionValue) ;
optionRank = document.Myform .MyList2.option s.length;
document.Myform .MyList2.option s[optionRank]=optionObject;
}

if(elem.options[elem.selectedIn dex].value==2)
{
var optionText = "SomeText1" ;
var optionValue = 0;
var optionObject = new Option(optionTe xt,optionValue) ;
optionRank = document.Myform .MyList2.option s.length;
document.Myform .MyList2.option s[optionRank]=optionObject;
optionText = "SomeText2" ;
optionValue = 1;
optionObject = new Option(optionTe xt,optionValue) ;
optionRank = document.Myform .MyList2.option s.length;
document.Myform .MyList2.option s[optionRank]=optionObject;
}
}
</script>

<script language="vb" runat="server">
Sub Save_click( ByVal Sender as Object, ByVal As
ImageClickEvent Args )

//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.selecte dIndex and it returns me 0. What am I doing wrong?

Any helps is greatly appreciated!

Jonathan

Nov 22 '05 #1
1 2020
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:DropDownLi st id="MyDropDownL ist1" onChange="LoadC ontent(this);"
runat="server">
<asp:ListItem value="0">&nbsp ;</asp:ListItem>
<asp:ListItem value="1">MyCho ice1</asp:ListItem>
<asp:ListItem value="2">MyCho ice2</asp:ListItem>
</asp:DropDownLis t>

<select id="MyList2" runat="server">
<option></option>
</select>

<asp:imageButto n id="Save" imageURL="./Images/Save.gif"
onclick="Save_c lick" runat="server" />

<script language="javas cript">
function LoadContent(ele m)
{
if(elem.options[elem.selectedIn dex].value==1)
{
var optionText = "MyText1";
var optionValue = 0;
var optionObject = new Option(optionTe xt,optionValue) ;
optionRank = document.Myform .MyList2.option s.length;
document.Myform .MyList2.option s[optionRank]=optionObject;
optionText = "MyText2";
optionValue = 1;
optionObject = new Option(optionTe xt,optionValue) ;
optionRank = document.Myform .MyList2.option s.length;
document.Myform .MyList2.option s[optionRank]=optionObject;
}

if(elem.options[elem.selectedIn dex].value==2)
{
var optionText = "SomeText1" ;
var optionValue = 0;
var optionObject = new Option(optionTe xt,optionValue) ;
optionRank = document.Myform .MyList2.option s.length;
document.Myform .MyList2.option s[optionRank]=optionObject;
optionText = "SomeText2" ;
optionValue = 1;
optionObject = new Option(optionTe xt,optionValue) ;
optionRank = document.Myform .MyList2.option s.length;
document.Myform .MyList2.option s[optionRank]=optionObject;
}
}
</script>

<script language="vb" runat="server">
Sub Save_click( ByVal Sender as Object, ByVal As
ImageClickEvent Args )

//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.selecte dIndex 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("M yList2")
Jonathan

Nov 22 '05 #2

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

Similar topics

1
381
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);" 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>
6
2145
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 that the HtmlSelect is populated is via a combination of client-side javascript and another aspx page (launched by the javascript). Anyway, everything seems to work just fine in terms of populating the HtmlSelect. However, when I postback the...
0
1738
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 completly disapear, the correct number show up without binding thus i know that its getting the correct values from teh dbase. here is teh code ive left in the the databind bit.. //table //add table and adjust rows according to dbase.
1
2264
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 because this is a client side operation(no server intervention is required), I wrote the JavaScript below to add account number entered in a text box to the list control, this works fine, the client can
4
2654
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 control, DropDownList, that initiates a postback when the option, AutoPostBack is set to true...so you can either have it postback when the user changes it immediately or not do anything when the user changes it.
2
5807
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 WithEvents Fruits As System.Web.UI.HtmlControls.HtmlSelect Protected WithEvents Results As System.Web.UI.WebControls.Label Protected WithEvents Button1 As System.Web.UI.WebControls.Button … Private Sub Page_Load(ByVal sender As System.Object, ByVal...
3
2090
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. When the page is rendered, the control is empty. Here is the code: In the web form: Dim UControl As AugmentedDropDownList =
1
2235
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"; //<----NOT WORKING ctrlsPlaceHolder.Controls.Add(m); this.DataBind();
0
8196
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8637
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7192
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6122
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4090
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2623
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1507
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.