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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:23:44+00:00 2026-06-12T01:23:44+00:00

I am trying to reacquaint myself with jQuery and am having difficulty getting started.

  • 0

I am trying to reacquaint myself with jQuery and am having difficulty getting started.

In the code below I am trying to say “When the DOM is ready, bind an alert to the change event of the ‘choice’ div, which is actually a select element on a form. When I reload the form though the alert is showing immediately, and does not show when I make a new selection.

Here’s the code:

$(document).ready(doBind());

function doBind() {
    $('#choice').change(myAlert('Choice has been changed!'));    
}

function myAlert($msg) {
    alert($msg);
}
  • 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-12T01:23:45+00:00Added an answer on June 12, 2026 at 1:23 am

    You need to differentiate between function references and invocations (calls). When you associate an event handler or callback you want a function reference which will then be invoked at the proper time. Once you pass arguments and add (..) (or a nullary ()) to a function reference it is invoked. If you do that during binding, then the function will be invoked at binding time and the output of the function will be bound rather than binding the reference (which would allow for the normally expected, later invocation).

    You should change both of your bindings as follows:

       $(document).ready(doBind); //Now a reference to that function
    
        function doBind() {
            $('#choice').change(function() { myAlert('Choice has been changed!');});    
           //New anonymous function reference which allows for arguments and is conventionally used
        }
    
        function myAlert($msg) {
            alert($msg);
        }
    

    A couple simple examples to highlight the differences in syntax and the use of ().

    The function below would take a function reference. as an argument and then execute it internally (basically how handlers and callbacks work).

    functionWrapper = function(funk) {
      //Do something else
      funk()
    }
    

    The now popular anonymous function declaration followed by immediate invocation: functions will often be written function() {...}() which causes the reference to the newly created function to be immediately invoked with any arguments provided (useful in JavaScript to enforce scoping). Arguments in either case are then available as parameters in the function, so whatever is in the invocation (..) maps to what would be declared in the function(..) but focusing on reference vs. call is the main issue for your question.

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

Sidebar

Related Questions

Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
Trying to do this, but is it wrong? Below is my style and script
Trying to build a Metro app using Javascript and having issues with IndexedDb. I
Trying to do a bit of jquery for a landing page I'm putting up.
Trying to find the source code to the Open licenses AlertDialog screen (at least
Trying to develop hello world, but getting force close error on emulator. thanks in
trying to work out how to install zipArchive extension with MAMP, but not having
Trying to create an array of structs (new to C), but I am getting
Trying to download docs from the Google Docs using Java client library and getting
Trying to set RowHeight like this(in code): dgvTruckAvail.RowTemplate.Height = 48; Doesnt' work. I also

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.