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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:50:01+00:00 2026-06-12T16:50:01+00:00

The server sends some JSON. It contains a list of structured data. I display

  • 0

The server sends some JSON. It contains a list of structured data. I display this data as a list of textboxes, each of which has its own onClick event. On click, the value of the textbox is set to whatever is in the structured data (which is an unique ID, which means that each textbox should display the ID on click).

When I first click on any textbox, its value is set correctly — with the ID from the data from the server. But as I click on other textboxes, they display IDs from the first-click textbox!

I’ve tried both closure var and $.proxy(), but they doesn’t seem to work. I’ve checked the contents of myAttribute and they change on each iteration of the $.each() function. The click() event, however, seems to be evaluated at “runtime” and doesn’t update.

The questions are:

  1. How do I fix my problem, so that myProcessedAttribute will contain the correct data instead of the data on first click?
  2. I feel my approach of having four nested functions might not be best practice.. Or is it?

Code:

$.ajax({
  [...]
  success: function (data) {
    [...]
    $.each(data.listOfData, function () {
      [...]
      var myAttribute = this.myCoolAttribute; // <-- closure
      jQuery('<p/>')
      [...]
      .click(function () {
        var myProcessedAttribute = process(myAttribute);
        [jquery ui dialog...]
        create: function () {
          // it always contains the same data
          // the data on first click, after that, it never changes.
          $("#myDialog").html(myProcessedAttribute);
        }
      });
    });
  }
});

EDIT: I’ve just put alert(myProcessedAttribute) in click() and create events. In the former event, the alert displayed correct data. In latter event, the alert was displayed only on first click, but it never appeared again on subsequent clicks!

MY SOLUTION: I thought that on calling .dialog({…}) the new dialog replaces the old one, but I was wrong. I’ve solved the problem by destroying the old dialog before creating a new one.

BETTER SOLUTION: See answer below.

  • 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-12T16:50:03+00:00Added an answer on June 12, 2026 at 4:50 pm

    “create” event is called when dialog is created.
    Second time you open dialog, create event is not fired, because dialog object already exist on that element.
    If you want different values on same dialog widget, use “open” event.
    This is a sample

    http://jsfiddle.net/RaWrC/

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

Sidebar

Related Questions

My back end is my Rails server which sends JSON data to my front
I have following Situation, Server A sends some data (HTML form) to server B,
I'm sending some data to an external URL using Curl. The server sends me
I'm looking for a way to send some hidden form-data to a Django-server, which
I have an app [iphone], that sends to a server some times [using json],
I have a page, it has a drop down list, which contains the names
I'm on a page which sends a request to server side for a list
I need an app that sends an UDP packet to some network server and
My Javascript needs to send some data to a server when the page closes,
I am wanting to send some data to a server from a client application

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.