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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:43:53+00:00 2026-06-13T05:43:53+00:00

I have a div id called modalpage and have css. I need a javascript

  • 0

I have a div id called modalpage
and have css. I need a javascript function which can dynamically shows popup for 20 mins and change in every 30 secs right now i have the following javascript function. Can anybody help me please

<script language="javascript" type="text/javascript">
function revealModal(divID)
{
    window.onscroll = function () { 
        document.getElementById(divID).style.top = document.body.scrollTop;
    };
    document.getElementById(divID).style.display = "block";
    document.getElementById(divID).style.top = document.body.scrollTop;
}

which is called by a input id button.

<input id="Button1" type="button" value="Click here" onclick="revealModal('modalPage')" />

Thanks


This is what i came up with

function revealModal(divID)
{
var i = 1;
divID.replace('*', i);
setInterval(function(){revealModal(divID)},1000);
i = i + 1;
if (i == 3) i = 1;
var div = getElementById(divID)
window.onscroll = function () { document.getElementById(divID).style.top =       document.body.scrollTop; };
document.getElementById(divID).style.display = "block";
document.getElementById(divID).style.top = document.body.scrollTop;
}

but this is not working its showing the modular_3 every time. is it because of all three divs are in the same file ??

<input id="Button1" type="button" value="Click heres" onclick="revealModal('modalPage_*')" />
  • 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-13T05:43:54+00:00Added an answer on June 13, 2026 at 5:43 am

    Well, for one thing don’t put that set interval inside the function. That would start a never ending cycle on the first click that would keep triggering the div id it was passed.

    What you should probably do is keep an array of id’s that should be updated and loop through that in the function…

    var divs = [];
    
    function addID(id)
    {
        divs.push(id);
    }
    
    function revealModal()
    {
        for(var i = 0; i < divs.length; i ++)
        {
            var div = getElementById('modalPage_' + divs[i]);
    
            window.onscroll = function () { 
                div.style.top = document.body.scrollTop; 
            }
    
            div.style.display = "block";
            div.style.top = document.body.scrollTop;
        }
    }
    
    setInterval(function(){revealModal()},1000);
    

    And your html buttons:

    <input id="Button1" type="button" value="Click heres" onclick="addID('1')" />
    <input id="Button2" type="button" value="Click heres" onclick="addID('2')" />
    <input id="Button3" type="button" value="Click heres" onclick="addID('3')" />
    

    Now consider this – I don’t really understand your request. It looks like a bunch of others don’t understand either. The way I saw it was you want to reveal a div on click and make sure it updates every nth seconds. In this case, it looks like you chose 1000 ms, or every 1 second even though you said you wanted every 30 seconds. Fair enough, change that 1000 to 30000.
    It looks like the ONLY update you do is make sure it sticks to a certain position on the screen and NOT updates the content.

    So what I’ve done is make the interval outside the function so it is always going. Then on click you push the id into the divs array where the interval will update only what is inside the loop. While conceptually this will work, it seems like a bad way to do it.

    You should just use an easy library like jquery and place a scroll listener that updates the position whether or not they’re revealed. Seeing as you specified jquery in your tags but don’t use a lick of it in your example, I assume that means you’re not entirely familiar with the library.

    This could be done by simply adding a class of “modal” to every modal div and using this:

    $(document).ready(function(){
        $(window).scroll(function(){
            $('.modal').css('top', $(window).scrollTop() + 'px');
        });
    
        $('.modal').on('click', function(){
            $(this).css('display', 'block');
        });
    });
    

    Of course you would need to call the jquery library before this call for this to work.

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

Sidebar

Related Questions

I have a div id css called frontwidth which holds 1 img 1 title
I have a div called images_box which has a width of 277px . Within
I have a div called divContainer inside which i have few input elements like
I have a frame which is 760px wide. I then have a div called
If I have a container div called #container which has a bunch of .inside
Using CSS I have set a DIV called 'tidy' to invisible and width 0px.
I have a div called target which is centred and displayed over a google
I have div class called .stage which is a stage of a questionnaire <div
I have a div called address which as a textarea. When I click a
i have an div called foo. This is the css for the div: background-color:

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.