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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:00:31+00:00 2026-05-16T08:00:31+00:00

I’m trying to make a simple in in-page popup called like this: var test

  • 0

I’m trying to make a simple in in-page popup called like this:

var test = new popObject({}); //JSON options

and I’m having trouble because when I create two in a row, and call show() on the first one, the second one always shows. Both are created, but they aren’t separate somehow, despite being called with new. What am I doing wrong here? I’ve included my code, but I have removed out the irrelevant functions for compactness.

function popObject(options) {   
//functions

show = function() {
    console.log(boxselector);
    jQuery(boxselector).css("display", "block");
    return jQuery(boxselector);
}

var hide = function() {...}
var update = function(updateOptions) {...}
var calcTop = function(passedHeight) {...}
var calcLeft = function(passedWidth) {...}
var calcHeight = function(passedHeight) {...}
var stripUnits = function(measure, auto) {...}
var destroy = function() {...}

//public functions

this.show = show;
this.hide = hide;
this.update = update;
this.destroy = destroy;

//constants

name = options.name; //name should never be changed.
boxselector = ".boxcontainer[name=" + options.name + "]";
boxbodyselector = ".boxbody[name=" + options.name + "]";
boxtitleselector = ".boxcontainer[name=" + options.name + "]"
boxboxselector = ".boxbox[name=" + options.name + "]"
title = options.title;
content = options.content;  
width = options.width;
height = options.height;

this.name = name;
this.selectors = [boxselector, boxbodyselector, boxtitleselector, boxboxselector]
this.title = title;
this.content = content;
this.width = width;
this.height = height;

//variables

popupHtml = ...

//init code

jQuery("#dropzone").append(popupHtml); this.init = null;
jQuery(".boxbox[name=" + name + "]").css("top", calcTop(width));
jQuery(".boxbox[name=" + name + "]").css("left", calcLeft(height));
jQuery(".boxbody[name=" + name + "]").css("height", calcHeight(height));
}
  • 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-16T08:00:32+00:00Added an answer on May 16, 2026 at 8:00 am

    This is because you’re declaring a lot of variables in the global scope. Try the following code instead:

    function popObject(options) {   
    //functions
    
    this.show = function() {
        console.log(boxselector);
        jQuery(boxselector).css("display", "block");
        return jQuery(boxselector);
    }
    
    var hide = function() {...}
    var update = function(updateOptions) {...}
    var calcTop = function(passedHeight) {...}
    var calcLeft = function(passedWidth) {...}
    var calcHeight = function(passedHeight) {...}
    var stripUnits = function(measure, auto) {...}
    var destroy = function() {...}
    
    //public functions
    
    this.show = show;
    this.hide = hide;
    this.update = update;
    this.destroy = destroy;
    
    //constants
    
    var name = options.name; //name should never be changed.
    var boxselector = ".boxcontainer[name=" + options.name + "]";
    var boxbodyselector = ".boxbody[name=" + options.name + "]";
    var boxtitleselector = ".boxcontainer[name=" + options.name + "]"
    var boxboxselector = ".boxbox[name=" + options.name + "]"
    var title = options.title;
    var content = options.content;  
    var width = options.width;
    var height = options.height;
    
    this.name = name;
    this.selectors = [boxselector, boxbodyselector, boxtitleselector, boxboxselector]
    this.title = title;
    this.content = content;
    this.width = width;
    this.height = height;
    
    //variables
    
    var popupHtml = ...
    
    //init code
    
    jQuery("#dropzone").append(popupHtml); this.init = null;
    jQuery(".boxbox[name=" + name + "]").css("top", calcTop(width));
    jQuery(".boxbox[name=" + name + "]").css("left", calcLeft(height));
    jQuery(".boxbody[name=" + name + "]").css("height", calcHeight(height));
    }
    

    Note all the vars that weren’t there before. This defines them as local to the function, and thus local to your object (and also, essentially, private… use this. instead of var to make public members).

    Anything that isn’t declared with a var or a this. is considered global. So, when you called show(), it used the global show, which referenced the object that was created later.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Basically, what I'm trying to create is a page of div tags, each has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.