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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:12:52+00:00 2026-06-14T15:12:52+00:00

(My code is also here: http://jsbin.com/urupig/4/edit Next and Previous button is working but Jump

  • 0

enter image description here

(My code is also here: http://jsbin.com/urupig/4/edit

“Next” and “Previous” button is working but “Jump” button does not work.)

Hello, I am newbie of JavaScript and CoffeeScript.

I want to extract “Jump” element and want to jump to each image from jQuery UI menu.

Below code uses Flickr API for image. At first, Ajax communication was done and the URLs of images was loaded.

I want to jump each image but when children of “Jump” element was clicked, “index is out of number” was written in console.

HTML:

<body>
<ul id="menu">
    <li><a href="#" id="next">Next</a></li>
    <li><a href="#" id="previous">Previous</a></li>
    <li>
        <a href="#" id="jump">Jump</a>
        <ul id="jump_ul">
        </ul>
    </li>
</ul>
<br />
<div id="images"></div>
</body>

CoffeeScript:

class PhotoTable2
  json: null
  number: null

  constructor:(number) ->
    @number = number

  getData:(successCallback) =>
    $.getJSON(
      'http://www.flickr.com/services/rest/?jsoncallback=?'
        format : 'json'
        method : 'flickr.photos.search'
        api_key : '7965a8bc5a2a88908e8321f3f56c80ea'
        user_id : '29242822@N00'
        per_page : @number
      (data) =>
        @json = data.photos.photo;
        successCallback?())

  url:(index) ->
    item = @json[index]
    itemFarm = item.farm
    itemServer = item.server
    itemID = item.id
    itemSecret = item.secret
    itemPathList =
      'http://farm' + itemFarm + '.static.flickr.com/' + itemServer +
      '/' + itemID + '_' + itemSecret + '_m.jpg'

  putPhoto:(index) ->
    if (0 <= index and index <= (@number - 1))
      $('#images').empty()
      $('#images').append(
        $('<h3></h3>')
          .text(@json[index].title)
        $('<a></a>')
          .append(
            $('<img />')
              .attr('src', @url(index))))
    else
      console.log('index is out of number')

    console.log('index: ', index)

$ ->
  index = 0

  photo_table2 = new PhotoTable2(5)
  photo_table2.getData(successCallback = ->
    console.log('Data loaded',photo_table2.json)

    photo_table2.putPhoto(index)

    $('#next')
      .click ->
        index++
        photo_table2.putPhoto(index)

    $('#previous')
      .click ->
        index--
        photo_table2.putPhoto(index)

    for i in [0..(photo_table2.number - 1)]
      $('#jump_ul').append(
        $('<li></li>').append(
          $('<a></a>')
            .text(photo_table2.json[i].title)
            .click ->
              photo_table2.putPhoto(i)
            console.log(i)
        )
      )

    $("#menu").menu()
  )

Thank you for your kindness.

  • 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-14T15:12:53+00:00Added an answer on June 14, 2026 at 3:12 pm

    You’re having the standard “closure in a loop problem”. You’ll notice that console.log('index: ', index) always says 5; that’s because the click handlers end up sharing one reference to the same i and the value of that i will be the final value that i had in the for i in [0..(photo_table2.number - 1)] loop.

    The standard solution is to wrap the loop body in a self-executing function to force i to be evaluated when you want it to be. CoffeeScript provides do (see the bottom of that section) specifically for this purpose:

    for i in [0..(photo_table2.number - 1)]
      do (i) ->
        # Continue as before
    

    Demo: http://jsbin.com/urupig/5/edit

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

Sidebar

Related Questions

HI all. You can see the code right here: http://jsbin.com/egixa5/5/edit . I'm trying to
Please look at the code here : http://jsbin.com/esokic/10/edit#source When I click on customer support
I finally got some parts working here: http://jsfiddle.net/trXBr/5/ but when I put the code
I am using cody sherman's javascript code here: http://codysherman.com/tools/infinite-scrolling/code I am also using a
Here is the code (also at http://pastebin.com/yw5z2hnG ): #include <iostream> #include <vector> using namespace
In the followin flex Code : Also viewable at : http://www.cse.epicenterlabs.com/checkBoxDg/checkBoxDg.html 1. Add a
The example here http://mongoosejs.com/docs/populate.html Provides the following code var story1 = new Story({ title:
I'm attempting to utilize some code found here: http://androidtabs.googlecode.com/svn/trunk/ This includes the bases classes
Does anyone know of a good tutorial to achieve this? (as seen here: http://www.contrastrebellion.com/
I did this http://reboltutorial.com/images/rebol-iis.png as explained here but it was for IIS 6 http://rebolforum.com/index.cgi?f=printtopic&topicnumber=39&archiveflag=new

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.