473,687 Members | 3,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing the text of a div

5 New Member
I'm trying to update a div based on the selection from a select. I've found many pages, including one on here that describes the way I am doing this is correct but it still fails.

I get the error "Object doesn't support this property or method" at the line document.getEle mentByID("lblDe scription").fir stChild.nodeVal ue = aPackageDescrip tions[i]. Here is the code.

Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript">
  2. var aPackageDescriptions = new Array()
  4. aPackageDescriptions[0] = "Rollin VIP"
  5. aPackageDescriptions[1] = "Don't be late."
  6. function ShowDescription(i)
  7. {
  8.     document.getElementByID("lblDescription").firstChild.nodeValue = aPackageDescriptions[i]
  9. }
  11. </script>
  12.     <table>
  13.     <tr>
  14.         <th>Package Plan</th>
  15.         <td>
  16.             <select name="ddlPackagePlan" onChange="ShowDescription(ddlPackagePlan.selectedIndex)">
  17. <option value="1">Test Package</option>
  18. <option value="2">Meet me at the gate.</option>
  19.             </select>
  20.         </td>
  21.     </tr>
  22.     <tr>
  23.         <th>&nbsp;</th>
  24.         <td>
  25.             <fieldset>
  26.             <legend>Description</legend>
  27.                 <div id="lblDesciption">&nbsp;</div>
  28.             </fieldset>  
  29.     </table>
Does anyone see something wrong with this? Any help is appreciated.
May 11 '07 #1
3 1580
5 New Member
<div id="lblDescipti on">&nbsp;</div>
This is actually "lblDescription ." It was a typo from copy-paste. Doesn't work with the correct spelling.
May 11 '07 #2
5,390 Recognized Expert Moderator Expert
the following code works :) ... compare it to yours please ... there were some closing tags of td, tr missing, use 'getElementById ' correct, have a look at the onChange-change ;)

Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript">
  2.     var aPackageDescriptions = new Array()
  4.     aPackageDescriptions[0] = "Rollin VIP"
  5.     aPackageDescriptions[1] = "Don't be late."
  7.     function ShowDescription(i) {
  8.         document.getElementById("lblDescription").firstChild.nodeValue = aPackageDescriptions[i]
  9.     }
  10. </script>
  12. <table>
  13.     <tr>
  14.         <th>Package Plan</th>
  15.         <td>
  16.             <select name="ddlPackagePlan" 
  17.                 onChange="ShowDescription(this.selectedIndex)">
  18.                     <option value="1">Test Package</option>
  19.                     <option value="2">Meet me at the gate.</option>
  20.             </select>
  21.         </td>
  22.     </tr>
  23.     <tr>
  24.         <th>&nbsp;</th>
  25.         <td>
  26.             <fieldset>
  27.                 <legend>Description</legend>
  28.                 <div id="lblDescription">&nbsp;</div>
  29.             </fieldset>
  30.         </td>
  31.     </tr>
  32. </table>
May 11 '07 #3
5 New Member
Hmm, I'm usually strict on the proper HTML... guess I missed that somehow. Thank you for the help, it works well now.
May 11 '07 #4

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

Similar topics

by: Cengiz Ulku | last post by:
Hi all, I know now how to change the font name of a RTF file in a RTB control using, for example: RTextBox1.SelFontName = cmbFonts.Text I have a RTF file -created with Word- displayed in a RTB control. Whenever I change the font type during the runtime by selecting a font name from a combobox -of all system fonts, the text changes its font correctly but I loose some formatting such as a bold text and/or titles become normal text.
by: ehm | last post by:
I am working on creating an editable grid (for use in adding, deleting, and editing rows back to an Oracle database). I have a JSP that posts back to a servlet, which in turns posts to a WebLogic SFSB and, from there, to the database. On the front end, all cells appear as text fields. However, for certain cells, when the user clicks on the cell, the text field turns into a drop-down field (i.e. Select object), defaulting to the value...
by: pablo | last post by:
Dear NGers, I want to keep some images just left of some DIVs. But a change in text size leaves my images at the original position. Which event is generated by changing the text size from the toolbar?? tia pablo k
by: martin | last post by:
I needed a way to display calculated, multiple, changing values (numerical sums) as users interacted with the page, and do this without going back to the server to load the page again. What I finally settled on was <input type=button...> without an "onClick" attribute (because the purpose of the buttons was only for displaying values). It works fine except they look and act like buttons. No big deal, but is there a better way?
by: Frostillicus | last post by:
Hi, I've written some javascript to randomly choose a classical music composer's picture and sample audio and display it on my home page (http://marc.fearby.com/), and this works fine in Mozilla but has problems in IE. Here's the code: imagestring = "<img src=\"" + imagedir + composers + "\" />"; objimage.innerHTML = imagestring;
by: John Smith | last post by:
Hey folks, I've got a combobox (DropDown List) in a windows form application which is bound to a DataSet. It's value is set to a numeric ID. It's visible text is set to a date. I need to make it so that the first item shows the words "Most Recent" instead of the date. I've tried setting the SelectedItem, Text, and SelectedText of the list box to "Most Recent", when the SelectedIndex changes to 0, but nothing happens.
by: Sakharam Phapale | last post by:
Hi All, How to preserve the old font properties while changing new one? I posted same question 2 months back, but I had very small time then. eg. "Shopping for" is a text in RichTextBox and already formatted as "Shopping" ---Bold "for" -----Regular Now I want to underline whole text by preserving old style i.e. Bold and
by: samonline | last post by:
Dear friends, I have written a little program to read the source of a web page into a Rich Text Box. Now I want to find a specific integer value in that text box and take it into a variable. That integer value in the web page changes from time to time, but the text before that integer won't change. How can I get the integer into a variable? please help me... Eg: <body> .... Customer base- 2200..... </body> here the non changing string...
by: sphinney | last post by:
I have a datasheet style form with textbox (MyTextBox) that has the Text Format property set to "Rich Text". It is bound to a memo field in a table. How do I change the text or highlight color of certain text in the textbox such that the formating is saved in an underlying memo field? My situation is a little different than other posts I read. Most posts show how to find and select certain text in a textbox, and then change the formating...
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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,...
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...
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...
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();...
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...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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

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.