Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7755563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:36:02+00:00 2026-06-01T12:36:02+00:00

I have a problem with this script. At first I had the <div> s

  • 0

I have a problem with this script. At first I had the <div>s hard-coded and it was working fine. But then I needed to alter the navigation bar dynamically because I changed the (number of) links.

The problem is that the id’s are not registering when they are injected with element.innerHTML = (html string).

How can I fix this?

Here is the code:

javascript:

 function constructNav() {
   var submenu_layer_innerHTML = "";
   var top_nav_innerHTML = "<UL class=\"nav_category\">";
   for (i=0; i<links.length; i++) {
     submenu_layer_innerHTML = "<div class=\"submenu\" id=\"submenu" + i + "\" onMouseOut=\"timeHideNav('" + i + "','1000')\"> </div>";
     top_nav_innerHTML += "<LI id=\"link" + i + "\"><a href=# onMouseOver=\"expandNav('" + i + "');\">" + links[i] + "</a></LI>";
   }
   top_nav_innerHTML += "</UL>";
   document.getElementById("top_nav").innerHTML = top_nav_innerHTML;
   document.getElementById("submenu_layer").innerHTML = submenu_layer_innerHTML;
 }

html:

<script type="text/javascript" src="scripts.js"> </script>
<script type="text/javascript">
var links =["link 1",
    "link 2",
    "link 3",
    "link 4",
    "link 5",
    "link 6"];
</script>

<body onLoad="constructNav();">

<div id="submenu_layer"> </div>
<div id="top_nav"> </div>

I’m getting this error in firefox:

  line 35: document.getElementById("submenu"+pageNo) is NULL
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:36:03+00:00Added an answer on June 1, 2026 at 12:36 pm

    You are overwriting submenu_layer_innerHTML during each iteration of the for loop. Make sure to use +=.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

THIS IS THE FULL SCRIPT http://goo.gl/HoCxk I have a problem with this function: $('.message').click(function(){
I have this .bat script which I use to maven package my application. Problem
I have this html code <html> <head> <title>JQuery Problem 2</title> <script type=text/javascript src=jquery-1.4.min.js></script> <script
first I have to admit this might be a pretty specific problem. In a
I thought I finally had managed to write my first init.d script properly but
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have problem with this code: file = tempfile.TemporaryFile(mode='wrb') file.write(base64.b64decode(data)) file.flush() os.fsync(file) # file.seek(0)
Hi i have problem with this code, i found it on the internet and
i am a beginner and i have a problem : this code doesnt compile
I have this problem I'm hoping someone knows the answer to. I have an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.