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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:15:14+00:00 2026-06-10T19:15:14+00:00

I’ve written a program that includes a form that the user interacts with. Because

  • 0

I’ve written a program that includes a form that the user interacts with. Because there are lots of events bound to different buttons I have written a loop that parses some JS that contains the form input information. Here is some example data:

var value = 0,
forms = {
    place_controls : {
        attrs : {
            'class' : 'place-form'
        },
        input : {
            place_x : {
                attrs : {
                    type : 'text',
                },
                events : {
                    change : function () {
                        value = 10;
                    }
                }
            },
            place_y : {
                attrs : {
                    type : 'text',
                },
                events : {
                    change : function () {
                        value = 50
                    }
                }
            }
        }
    }
}

The data is then parsed by this:

    $.each(forms, function (form_index, form) {

    var $form_markup = $('<form>').attr(form.attrs);
    // Next: loop through each input element of the form we've reached
    $.each(form.input, function (element_index, element) {

        var $elem = $('<input>').attr(element.attrs);
        $elem.appendTo($form_markup);

        if (element.events !== undefined) {

            $.each(element.events, function (event_index, event) {

                $elem.bind(event_index, event);
                //$form_markup.on(event_index, $elem, event);
            });
        }
    });

    $form_markup.appendTo($form_goes_here);
});

As you can see, I’m using .bind() at the moment, however I want to use .on(). Unfortunately, when I do this all of the items within a form are bound to the last event parsed by the function. When I use .bind() everything works as planned – i.e. Clicking on ‘place_x’ sets value to 10, clicking ‘place_y’ sets value to 50.

When using .on(), whichever I change sets value to 50, which I am assuming is because the last function is becoming bound to each event.

Can anybody see what I have done wrong?

Update: There are many different ways to do this, and I have subsequently changed how my code works, however this question is related to why .bind() is working and why .on() is not.

  • 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-10T19:15:15+00:00Added an answer on June 10, 2026 at 7:15 pm
    //$elem.bind(event_index, event);
    
    //It looks like you should just be using .on() like this
    $elem.on(event_index, event);
    

    The way it looks like you are trying to use .on() is in the live -bubbling- event sort of way, it looks like only the last event you are created is sticking, why each value just gets set to 50.

    //$form_markup.on(event_index, $elem, event);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I have a text area in my form which accepts all possible characters from
I need a function that will clean a strings' special characters. I do NOT

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.