473,889 Members | 2,031 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

client side handling of selectedIndexCh anged from an asp.net dropdownlist

34 New Member
If the user of my site changes their selection in a dropdownlist, I would like to handle that client side and based on what they chose it would populate a text box with different text.

I can figure out how to do this server side no problem, but how do I get to do this in javascript.

I have something like:

<asp:DropDownLi st ID="StatusDropD ownList" runat="server" >
<asp:ListItem Selected="True" Text="Released" Value="Released ">Released</asp:ListItem>
<asp:ListItem Text="Down" Value="Down">Do wn</asp:ListItem>
<asp:ListItem Text="Blocked" Value="Blocked" >Blocked</asp:ListItem>

</asp:DropDownLis t>

I have an text box that I want to populate based on what the user selects and I would like to do this in javascript...I cannot seem to get that function to work.

any suggestions?
thanks.
Aug 7 '07
15 27770
Frinavale
9,735 Recognized Expert Moderator Expert
Yeah that makes sense...

EmailTextBox is the ID of my asp:TextBox

I added the document.getEle mentByID... but still nothing.

just a blank text box.

does it need to be a regular html text box? or can I use an asp:textbox?

Thanks,

EmailTextBox may be what you have defined as the ID for your TextBox in your Asp...however, this is not necessarily the HTML ID of your textbox.

Run your website, right click and view the html code.
Find your text box and see if it is actually called EmailTextBox.
It likely isn't called that.

-Frinny
Aug 8 '07 #11
Frinavale
9,735 Recognized Expert Moderator Expert
Y
does it need to be a regular html text box? or can I use an asp:textbox?
When the page is rendered for the browser your asp:textbox is sent as <input type="text">.
Aug 8 '07 #12
JLC
34 New Member
Ok so here is my html code from when I am running my site. I think it's still called 'EmailTextBox', but I don's see the <input type='text'> part.
am I missing something?

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml" >
  6. <head><title>
  7.     Notify Dialog Page
  8. </title>
  9. <script type="text/javascript">
  10.     function EmailChangedText(ddid)
  11.     {
  12.         var selected = ddid.options[ddid.selectedIndex].value;
  13.         //alert(selected);
  14.         //EmailTextBox.Text = selected;
  15.         document.getElementById('EmailTextBox').nodeName = selected;
  16.     }
  17.  
  18. </script>
  19. </head>
  20.  
  21. <body>
  22. <form name="ctl01" method="post" action="NotifyDialog.aspx" id="ctl01">
  23. <div>
  24. <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTIxNzE0NjE4MQ9kFgICAw9kFgQCAQ8QD2QWAh4IT25DaGFuZ2UFMGphdmFzY3JpcHQ6IEVtYWlsQ2hhbmdlZFRleHQoU3RhdHVzRHJvcERvd25MaXN0KWRkZAIFDw9kFgIfAAUwamF2YXNjcmlwdDogRW1haWxDaGFuZ2VkVGV4dChTdGF0dXNEcm9wRG93bkxpc3QpZBgBBR5fX0NvbnRyb2xzUmVxdWlyZVBvc3RCYWNrS2V5X18WAQUNRW1haWxDaGVja0JveMewFogN+BDQiBmhFsWNTETBItfz" />
  25. </div>
  26.  
  27.    <div style="width: 525px; height: 300px">
  28.  
  29.    <!-- will eventually pull items from Davids db, but will hard code them for now -->
  30.     <select name="StatusDropDownList" id="StatusDropDownList" OnChange="javascript: EmailChangedText(StatusDropDownList)" style="width:158px;z-index: 100; left: 39px; position: absolute; top: 62px">
  31.     <option selected="selected" value="Released">Released</option>
  32.     <option value="Down">Down</option>
  33.     <option value="Blocked">Blocked</option>
  34.     <option value="Deploying">Deploying</option>
  35.  
  36. </select>
  37.  
  38.  
  39.  
  40.     <span style="z-index: 101; left: 39px; position: absolute; top: 104px"><input id="EmailCheckBox" type="checkbox" name="EmailCheckBox" /></span>
  41.  
  42.     <textarea name="EmailTextBox" rows="2" cols="20" id="EmailTextBox" OnChange="javascript: EmailChangedText(StatusDropDownList)" style="height:103px;width:440px;z-index: 102; left: 39px; position: absolute; top: 131px"></textarea>
  43.  
  44.     <input type="submit" name="SubmitButton" value="Submit" id="SubmitButton" style="width:50px;z-index: 103; left: 435px; position: absolute; top: 252px" />
  45.  
  46.     <span id="EmailLabel" style="z-index: 104; left: 66px; position: absolute;
  47.            top: 105px">Send Email</span>
  48.     <span id="StatusLabel" style="z-index: 106; left: 39px; position: absolute;
  49.            top: 36px">Status</span>
  50.  
  51.    </div>
  52.  
  53. <div>
  54.  
  55.     <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWCAL4nMfMCALzxpLhCQK+ioLYCALf072eBgLVhpG4CgLk8P2jCAKi0/XgDAKyuOLUC7ksRSvFd3MZwYrtA1jKyRahVXWZ" />
  56. </div></form>
  57.  
  58. </body>
  59. </html>
  60.  
When the page is rendered for the browser your asp:textbox is sent as <input type="text">.
Aug 8 '07 #13
Frinavale
9,735 Recognized Expert Moderator Expert
I just took the code you had here and pasted into a simple HTML page and ran it with one change and it worked.

Change your JavaScript to be:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.     function EmailChangedText(ddid)
  3.     {
  4.         var selected = ddid.options[ddid.selectedIndex].value;
  5.         //alert(selected);
  6.         //EmailTextBox.Text = selected;
  7.         document.getElementById('EmailTextBox').value = selected;
  8.     }
  9.  
  10. </script>
This has been tested with your code and appears to work fine.

-Frinny

Ok so here is my html code from when I am running my site. I think it's still called 'EmailTextBox', but I don's see the <input type='text'> part.
am I missing something?
Aug 8 '07 #14
JLC
34 New Member
Frinny,

It works! I do not know why it didn't work when you sent that part the first time.

The .value doesn't show up in intellisense so I was trying others (obviously with no luck).

what is .value? is that eh Value in the asp:ListItem?

Thank you so much for all the help...I am relieved!

JLC

I just took the code you had here and pasted into a simple HTML page and ran it with one change and it worked.

Change your JavaScript to be:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.     function EmailChangedText(ddid)
  3.     {
  4.         var selected = ddid.options[ddid.selectedIndex].value;
  5.         //alert(selected);
  6.         //EmailTextBox.Text = selected;
  7.         document.getElementById('EmailTextBox').value = selected;
  8.     }
  9.  
  10. </script>
This has been tested with your code and appears to work fine.

-Frinny
Aug 8 '07 #15
Frinavale
9,735 Recognized Expert Moderator Expert
Frinny,

It works! I do not know why it didn't work when you sent that part the first time.

The .value doesn't show up in intellisense so I was trying others (obviously with no luck).

what is .value? is that eh Value in the asp:ListItem?

Thank you so much for all the help...I am relieved!

JLC
JavaScript does not apply to asp objects....it works on HTML objects. The .value lets you access the value of the HTML object in JavaScript.

Whenever I'm dealing with JavaScript or HTML or CSS I basically stick to what is outlined in the w3c website...you will find all your JavaScript answers there. Just beware that there's a lot of information on that site so be specific in your searches.

I'm glad everything's working!

Cheers!

-Frinny
Aug 8 '07 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

1
9101
by: Donal | last post by:
I have 3 related dropdowns. When the 1st is changed, the 2nd is updated, and when the 2nd is changed, the 3rd is updated. When i change the 1st dropdown (sites), the SelectedIndexChanged fires and the 2nd dropdown (spaces) is updated. However, 'spaces' no longer has a SelectedIndexChanged event. Where did it go to? If I change 'spaces' (2nd dropdown) before it gets updated by the 1st (sites), its SelectedIndexChanged is fired and the...
1
3476
by: Ravi | last post by:
Hi, I have a radio button list and a dropdownlist inside a repeater control. Want to hide or display the dropdownlist based on selection in radiobuttonlist. I can add the selectedindexchanged eventhandler for radiobuttonlist in itemdatabound,but cannot figure out which items dropdownlist in
5
2772
by: Ben | last post by:
I want to enable/disable a text field cleint side based on a value in a dropdownlist, what is the 'best'/'standard' approach for handling this in ..net? I know i just just throw an on change attribute on the server controls tag, but is that the 'right' way to do it? Thanks, Ben
0
322
by: Jeremy | last post by:
I have 2 DropDownList controls on an ASPX page and would like to set the selected text in one of them during the SelectedIndexChanged event of the other - and I'd like to do this all client-side. I'm hard-coding the content of both DDLs, so the content of each could be known ahead of time and therefore a round trip to the server would hopefully be totally unnecessary. Is this possible? If so, how? Thanks.
2
1952
by: Rea Peleg | last post by:
Hi all Is it possible to handle web controls events on client side??? I wrote a simple favascript function inside the <header> area of an aspx web form. This function is called on selectedIndexChanged event of server side radio button list, but i can not get there . During compilation, it seems like the dotnet asp service is looking for this function on that web form's (server side) code
3
1343
by: Eric | last post by:
I have a drop down list with an associated label. I want to take the selectedValue of the list and populate the text of the label when the value in the list is changed. I havent figured out how to access the controls through the script, however. Here's what I have: In the ASPX file: <script> function OnSelectedIndexChanged() {window.document.Form1.lblLogIDDate.Text =
6
5558
by: Julius Fenata | last post by:
Dear all, I have created client-side scripting to trigger event onChange from code-behind, like this: DropDownList1.Attributes = "GenerateArticleID()"; At the script on Windows Form, I added this function to have the value of DropDownList1
11
37036
by: J055 | last post by:
Hi I have a dropdown control which is constructed in another dropdown control SelectedIndexChanged event protected void ddlParamType_SelectedIndexChanged(object sender, EventArgs e) { // some other code DropDownList ddlGroups = new DropDownList(); ddlGroups.SelectedIndexChanged += new
5
2191
by: revbart | last post by:
Yep, that's me. I'll bet I've read a hundred articles somewhere or another, but I just can't get the thing to work. I'm working on a custom solution. One of the major UIs includes a calendar-style presentation. The navigation controls at the top of the calendar include four LinkButton controls (prevYear, prevMonth, nextMonth, nextYear) and two DropDownList controls (monthSelector, yearSelector). The DropDownList webcontrols are set with...
0
9810
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
10794
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...
1
10896
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10443
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...
1
8000
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
7153
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5830
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...
2
4251
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3259
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.