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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:24:42+00:00 2026-05-23T23:24:42+00:00

this is my html: <!DOCTYPE html> <html lang=en> <head> <meta charset=utf-8> <title>Something</title> </head> <body>

  • 0

this is my html:

<!DOCTYPE html>
 <html lang="en">
 <head>
   <meta charset="utf-8">
   <title>Something</title>
 </head>
 <body>
   <a href="http://www.google.com">Try Me!</a>
   <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
   <script>
$("a").click(function(event){
  for(id=0;id<=10;id++){
    setTimeout(function() {
      var local_id = id;
      window.open("http://www.mysite.com/characterID="+local_id,"", "win"+local_id, "width=100,height=100,resizable");
      }, 3000*id);
   }
   event.preventDefault();
});

   </script>
 </body>
 </html>

This link is opening each window 3 seconds after the next.

This is the row I need: http://www.mysite.com/characterID=1, http://www.mysite.com/characterID=2, http://www.mysite.com/characterID=3...

But it always opens http://www.mysite.com/characterID=11

How can I fix it?

Thank you…

  • 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-23T23:24:42+00:00Added an answer on May 23, 2026 at 11:24 pm

    This is a common issue.

    You’re overwriting local_id in the loop, and always referring to the same variable when the code runs. This is because JavaScript does not have block scope, just function scope.

    So to scope the id, you need to invoke a function, and define the variable (or function parameter) there.

    function createWindow(local_id) {
        setTimeout(function () {
            window.open("http://www.mysite.com/characterID=" + local_id, "", "win" + local_id, "width=100,height=100,resizable");
        }, 3000 * local_id);
    }
    
    for (id = 0; id <= 10; id++) {
        createWindow(id);
    }
    

    Or a similar patter would be to have the function return a function to the loop.

    function createWindow(local_id) {
        return function() {
            window.open("http://www.mysite.com/characterID=" + local_id, "", "win" + local_id, "width=100,height=100,resizable");
        };
    }
    
    for (id = 0; id <= 10; id++) {
        setTimeout( createWindow(id) , 3000 * id);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this html and css code: <!DOCTYPE html> <html lang=en> <head> <meta charset=utf-8
This html: <!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01//EN http://www.w3.org/TR/html4/strict.dtd> <html> <head><title>TD align test</title></head> <body>
This is my code: <!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN http://www.w3.org/TR/html4/loose.dtd> <html> <head>
this is my google-map code: <!DOCTYPE html PUBLIC -//WAPFORUM//DTD XHTML Mobile 1.0//EN http://www.wapforum.org/DTD/xhtml-mobile10.dtd> <html
this html is here : <!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN><html><head><META http-equiv=Content-Type content=text/html;
I have this html doc: <?xml version=1.0 encoding=utf-8?><!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.1//EN http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd>
I have this HTML which I'm working on: <!DOCTYPE html> <html lang=en> <head> <meta
I have this HTML form page: form1.html <!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01//EN http://www.w3.org/TR/html4/strict.dtd
Consider this HTML: <!DOCTYPE html> <html> <head> <title></title> <style type=text/css> div { position: relative;
If I have the following HTML: <!DOCTYPE html> <html> <head> <title>Test</title> <link href=base.css rel=stylesheet/>

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.