Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old May 22nd, 2007, 11:20 PM
Newbie
 
Join Date: May 2007
Posts: 7
Default dynamic menu problem with onchange event

Hi, I am trying to make a dynamic menu using javascript and an xml file. The structure of the page (test.html) is in the code below. When I load up the page the drop-down list is there, so I select a value from the list and it passes that value to the function to get the appropriate data and it prints out the values (which it does just fine).

The thing is when I select an item from the drop-down list the other html disappears (even the doctype, and drop down list), and it just displays the values... This is all happening on the same page (test.html), so I'm not sure what is going on. Would using "document.write" in the script mess it up so it only display the output from the function? Any help is appreciated, thanks.

Expand|Select|Wrap|Line Numbers
  1. <doctype etc...>
  2. <html>
  3. <head>
  4. <script type="text/javascript">
  5. function initMenu(value) {
  6. .. code to parse xml file and print out values
  7. }
  8. </script>
  9. </head>
  10. <body>
  11. <form name="myForm">
  12. <select name="mySelect" onchange="initMenu(this.value)">
  13. <option value="Item1">Item 1</option>
  14. <option value="Item2">Item 2</option>
  15. <option value="Item3">Item 3</option>
  16. <option value="Item4">Item 4</option>
  17. </select>
  18. </form>
  19. </body>
  20. </html>
  21.  
Reply
  #2  
Old May 23rd, 2007, 04:56 AM
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Age: 24
Posts: 5,310
Default

Heya, chobo. Welcome to TSDN!

Quote:
Originally Posted by chobo
Would using "document.write" in the script mess it up so it only display the output from the function?
When you use document.write, the script has to open the document for writing. If it is still loading, this isn't a problem b/c the document is still open.

On the other hand, once the document finishes loading, it is 'closed', and the only way to open it is to erase it and start over.

This would be why you're only seeing the output of your function.

What you'll want to do instead is to dynamically create a new element and insert it into the body of your document, or else alter the innerHTML property of a container element.
Reply
  #3  
Old May 24th, 2007, 07:42 PM
Newbie
 
Join Date: May 2007
Posts: 7
Default

Thanks for the help and information! I got it to work by cocantenating the output to a variable and using the innerHTML property.
Reply
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles