473,396 Members | 1,987 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.

Changing the text of a div

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.getElementByID("lblDescription").firstChi ld.nodeValue = aPackageDescriptions[i]. Here is the code.

Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript">
  2. var aPackageDescriptions = new Array()
  3.  
  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. }
  10.  
  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>
  30.  
Does anyone see something wrong with this? Any help is appreciated.
May 11 '07 #1
3 1559
<div id="lblDesciption">&nbsp;</div>
This is actually "lblDescription." It was a typo from copy-paste. Doesn't work with the correct spelling.
May 11 '07 #2
gits
5,390 Expert Mod 4TB
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()
  3.  
  4.     aPackageDescriptions[0] = "Rollin VIP"
  5.     aPackageDescriptions[1] = "Don't be late."
  6.  
  7.     function ShowDescription(i) {
  8.         document.getElementById("lblDescription").firstChild.nodeValue = aPackageDescriptions[i]
  9.     }
  10. </script>
  11.  
  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>
  33.  
May 11 '07 #3
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

3
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...
2
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...
2
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...
5
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...
7
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...
2
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...
7
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...
2
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...
7
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...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.