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 3999546
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:40:16+00:00 2026-05-20T07:40:16+00:00

i am using a javascript where in i am creating multiple div (say 5)

  • 0

i am using a javascript where in i am creating multiple div (say 5) at runtime, using javascript function, all the divs contain some text, which is again set at runtime, now i want to disable all the divs at runtime and have the page numbers in the bottom, so that whenever user clicks on the page number only that div should get visible else other should get disable, i have created a function, which accepts parameter, as page number, i enable the div whose page number is clicked and using a for loop, i disable all the other divs, now here my problem is i have created two functions, 1st (for adding divs and disabling all the divs except 1st) and writing content to it, and other for enabling the div whose page number is clicked, and i have called the Adding div function on body onload; now first time when i run, page everthing goes well, but next time when i click on any of the page number, it just gets enabled and again that AddDiv function, runs and re-enables all the divs..

Please reply why this is happening and how should i resolve my issue…

Below is my script, content for the div are coming using Json.

<body onload="JsonScript();">
<script language="javascript" type="text/javascript">
        function JsonScript()
        {
            var existingDiv = document.getElementById("form1");
            var newAnchorDiv = document.createElement("div");
            newAnchorDiv.id = "anchorDiv";

            var list = { "Article": articleList };
            for(var i=0; i < list.Article.length; i++)
            {
                var newDiv = document.createElement("div");
                newDiv.id = "div"+(i+1);
                newDiv.innerHTML = list.Article[i].toString();
                newAnchorDiv.innerHTML += "<a href='' onclick='displayMessage("+(i+1)+")'>"+(i+1)+"</a>&nbsp;";
                existingDiv.appendChild(newDiv);
                existingDiv.appendChild(newAnchorDiv);
            }

            for(var j = 2; j < list.Article.length + 1; j ++)
            {
                var getDivs = document.getElementById("div"+j);
                getDivs.style.display = "none";
            }
        }
       function displayMessage(currentId) {
            var list = {"Article" : articleList}
            document.getElementById("div"+currentId).style.display = 'block';
            for(var i = 1; i < list.Article.length + 1; i++)
            {
                if (i != currentId)
                {
                    document.getElementById("div"+i).style.display = 'none';
                }
            }
        }
    </script>    

Thanks and Regards

  • 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-05-20T07:40:17+00:00Added an answer on May 20, 2026 at 7:40 am

    Try adding return false; to the page link to prevent the page from being reloaded.

    newAnchorDiv.innerHTML += "<a href='' onclick='displayMessage("+(i+1)+");return false;'>"+(i+1)+"</a>&nbsp;";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using javascript, I'm creating some html content--some nested divs that are styled via a
I'm creating the following div using javascript, task_id is an int and person_name is
I'm using JavaScript to hide an image and show some text thats hidden under
I'm creating a game for the iPad using Phonegap, which means I'm using JavaScript/
I am using Javascript and am creating my function within a closure, the problem
Is there a way of creating a global function in Xul (using javascript, I
I am creating a property in a DOM element using javascript in a function
I am creating application in AIR using JavaScript. Many of my functions requires text
I am creating a large table dynamically using Javascript. I have realised the time
using Javascript, it is easy to programatically select the text inside a textarea or

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.