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

  • Home
  • SEARCH
  • 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 4243974
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:38:51+00:00 2026-05-21T03:38:51+00:00

I am having problems implementing a dynamic number of .live() events. There is a

  • 0

I am having problems implementing a dynamic number of .live() events.

There is a loop to determine how many pages to create links for returned from an ajax call.

Basically I get 1 of 3 (-1, 0, [object Object]) results depending on how I pass the number of pages inside the live event.

Here is how it stands now, where it only returns 0 for each live event. To get -1, I would remove the contractPage declaration and put that in the net.tsn.contract.log function, or [object Object] I would pass page in the live’s handler function.

for (var page=(contractId['pages']-1); page>=0; page--) {
    $("#jpgLinks").prepend("<span><a href='#' id='jpgLink"+page+"'><img src='img/JPG-Link_con-" + (page+1) + ".png' alt=''><br>Page " + (page+1) + "<\/a><\/span>");
    var contractPage = contractId['contract'] + "-" + page;
    $('#jpgLink'+page).live('click', function() {
        showWorkingDialog();
        net.tsn.contract.log(contractPage, "DOWNLOAD_JPG", '<?php echo $_GET['lead']; ?>');
    });
}
  • 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-21T03:38:52+00:00Added an answer on May 21, 2026 at 3:38 am

    Ah, I see what the problem is here. You need to make a closure to close the value of page for each live() event.

    Put this function somewhere in your code (before the for loop):

    function _contractPage(contractPage, page){
        return function(){
            contractPage = contractPage  + "-" + page;
            showWorkingDialog();
            net.tsn.contract.log(contractPage, "DOWNLOAD_JPG", '<?php echo $_GET['lead']; ?>');
        }
    }
    

    And then change your for loop like so:

    for (var page=(contractId['pages']-1); page>=0; page--) {
        $("#jpgLinks").prepend("<span><a href='#' id='jpgLink"+page+"'><img src='img/JPG-Link_con-" + (page+1) + ".png' alt=''><br>Page " + (page+1) + "<\/a><\/span>");
        var contractFunc = _contractPage(contractId['contract'], page);
        $('#jpgLink'+page).live('click', contractFunc);
    }
    

    Example: http://jsfiddle.net/T8UjA/

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

Sidebar

Related Questions

I am having problems implementing the following jQuery effect to my navigation. There will
I am having problems with implementing Observer pattern in my project. The project has
I am still having problems with figuring out how to create winforms in a
I'm having problems implementing IEnumerable<T> in my custom collection class in C++/CLI. Here is
I am having problems implementing my PHP/MySQL code into a jgrowl. If you are
I'm having problems implementing an asynchronous image loader to the following code. I read
I've bought the virtual gallery from flashden but I'm having problems implementing it.. I'm
I'm having problems implementing friendly SEO urls on my local (Mac OS X Snow
I'm having problems implementing classes in mootools since I can't use 'this' when I
I having some problems implementing IOC using windsor. I have several different implementations of

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.