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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:04:47+00:00 2026-06-04T21:04:47+00:00

I am creating a jquery plugin to attach events and event handlers at run

  • 0

I am creating a jquery plugin to attach events and event handlers at run time:

The HTML:

<table id="digitalInputsTable">
<thead>
    <th>Name</th>
    <th>Value</th>
    <th>State</th>
    <th>Enabled</th>
    <th>Polarity</th>
    <th>Ignore Reset</th>       
</thead>
<tbody>
    <tr>      
        <td>
            <span class="">Name1</span>     
        </td>
        <td>
            <span class="">0</span>
        </td>
        <td>
            <span class="">Normal</span>
        </td>
        <td>
            <input type="checkbox" value="true" class="" jqmon="0" jqreg="0" id="digitalInputsTable_checkbox_03">
        </td>
        <td>
            <select class="" jqmon="0" jqreg="0" id="digitalInputsTable_select_04">
                <option value="0=Alarm">0=Alarm</option>
                <option value="1=Alarm">1=Alarm</option>
            </select>     
        </td>
        <td>          
            <input type="checkbox" value="true" class="" jqmon="0" jqreg="0" id="digitalInputsTable_checkbox_05">       
        </td>
    </tr>
</tbody>

The Data Structure:

$("#digitalInputsTable").bindEvents({
    parentControl: "digitalInputsTable",
    controls: [
        {   
            id: undefined, 
            name: "checkbox", 
            idStartsWith: "digitalInputsTable_checkbox_",               
            event: "click", 
            callbackHandler: "checkboxCallback"             
        },
        {
            id: undefined,
            name: "checkbox",
            idStartsWith: "digitalInputsTable_checkbox_",
            event: "blur",
            callbackHandler: "blurCallback"
        },
        {
            id: undefined,
            name: "select", 
            idStartsWith: "digitalInputsTable_select_",                 
            event: "change", 
            callbackHandler: "selectCallback"               
        }
    ]   
});

The Plugin:

$.fn.bindEvents = function(options) {           
for(var i = 0; i < options.controls.length; i++) {      
    var control = options.controls[i];
    switch(control.name) {
        case "checkbox":
            control.name = ":checkbox";
            break;          
    }

    if(control.id) {
        // find control by ID.
        // Attach event to the control.
    }
    else if(control.idStartsWith) {         
        $("#" + options.parentControl).find(control.name + "[id^=" + control.idStartsWith + "]")
                                    .bind(control.event, function(e) {                                          
                                        function(ctrl) {                                                
                                            eval(ctrl.callbackHandler + "();");
                                        };                                          
                                    }(control));
    }
};

};

The Problem:
When I check the check box, I am not able to call the “checkboxCallback” callback function of the check box. May be I am using closure incorrectly. Please advise.

  • 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-04T21:04:48+00:00Added an answer on June 4, 2026 at 9:04 pm

    This is not a complete answer, but it should point you in the right direction. Basically when you loop over the options.controls and need to perform actions on them in the future, you need to use a closure to separate them.

    $.fn.bindEvents = function(options) {
        // loop through the controls
        for (var i = 0, control; control = options.controls[i]; ++i) {
            // close over the current item
            (function(ctrl) {
                // you can safely use ctrl now
    
                // call the callback like so
                ctrl.callbackHandler();
            }(control));
        }
    };
    

    Btw, don’t use eval to call the callback, just pass the function reference:

    callbackHandler: checkboxCallback
    

    I’ve added example of how to call it inside the $.fn.bindEvents function.

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

Sidebar

Related Questions

I'm creating a fork of the textchange jQuery plugin , which uses the jQuery.event.special
I'm creating a jquery plugin for sorting and pagination a table (I know that
What's the best jQuery plugin for creating a table with fixed header? It should
I'm creating a jQuery plugin that needs to do a bunch of stuff the
I wanted to create jquery plugin & started off creating a sample jquery plugin...But
I'm creating a webpage which uses jquery.transit plugin. I download the .js file and
I'm reading some tutorials now about jQuery.. function creating,plugin creation etc. but these tutorials
i am dynamically creating radio using jquery as shown belown. but they value only
I'm creating jQuery plugin: $.fn.myGrid = function () { return ???; } I want
I'm creating a jQuery plugin. So far it's working fine, but I'm having doubt

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.