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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:26:47+00:00 2026-06-15T03:26:47+00:00

I am attempting to create a timepicker inside of a popup form . I

  • 0

I am attempting to create a timepicker inside of a popup form. I am struggling with event delegation — I am capable of getting the timepicker to work outside of the form, but not inside.

My current code, which does not have the timepicker popup:

 $(document).ready(function() {
   $('#timepick').timepicker({
     showPeriod: true,
     showLeadingZero: true
   });
 });

$(function() {
    $( "#dialog-form" ).dialog({
        autoOpen: false,
        height: 300,
        width: 350,
        modal: true,
        buttons: {
            "Add Time": function() {
                    $( "#time-table tbody" ).append( "<tr>" +
                        "<td>" + time.value + "</td>" + 
                    "</tr>" ); 
                    $( this ).dialog( "close" );
            },
            Cancel: function() {
                $( this ).dialog( "close" );
            }
        },
    });

    $("#add-time").button().click(function() {
            $( "#dialog-form" ).dialog( "open" );
    });
});

This does not work inside of the popup box, only for #timepick outside of it. I know I somehow need to utilize the .on() jquery function.

        $(document).ready(function() {
            $('#timepick').on("click", function(){
                timepicker({
                showPeriod: true,
                showLeadingZero: true
            });
        });

Did not work either.

A pastebin of the current tryout:

http://pastebin.com/gta7TD47

EDIT:

So this MOSTLY works:

        $(document).ready(function() {
          $('#dialog-form').on('click','#time',function() {
            $('#time').timepicker({
                showPeriod: true,
                showLeadingZero: true
            });
          });
        });

The only problem is, it currently requires you to click on the box, which then adds the event handler, and then click off and click back on — so it requires a click before working. How do I get it to fire immediately? Somehow using .trigger()?

  • 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-15T03:26:48+00:00Added an answer on June 15, 2026 at 3:26 am

    You’re not delegating anything. You’re merely binding the event directly on the timepick element.
    If you want to delegate an event, you’ll need an aditional selector:

    $('body').on('click','.allElementsYouNeedSelector',function(){});
    

    The code above will apply the anonymous callback function as an event handler for all click events that are triggered on any element that has the allElementsYouNeedSelector class, anywhere in the $('body') tag.
    So if you want to delegate from, say your dialog-form element:

    $('#dialog-form').on('click','*',function()
    {//will be called when any child of the #dialog-form is clicked
    });
    

    Mind you, if you use the on method like this, it’s translated to the delegate method internally.

    Update:
    In light of your update, I must say: it makes no sense at all to delegate an event for an element that has a unique ID. Perhaps you could try this:

    $('#time').on('click',{showPeriod: true,showLeadingZero: true},timepicker);
    

    This binds a click listener to the #time element, and applies the timepicker method as an event handler, passing the object literal {showPeriod: true,showLeadingZero: true} as an argument, just like you’re doing. Of course, you can do the same thing using delegation:

    $('#dialog-form').on('click','*',function()
    {//regardles of which child was clicked, apply the timepicker method to #time
        $.timepicker.apply($('#time'),[{showPeriod: true,showLeadingZero: true}]);
    });
    

    As ever, to avoid having to scan the DOM on each call, you can add a closure

    $('#dialog-form').on('click','*',(function(time)
    {
        return function()
        {
            time = time || $('#time');//in case $('#time') didn't exist when function was created
            $.timepicker.apply(time,[{showPeriod: true,showLeadingZero: true}]);
        };
    }($('#time')));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I attempting to create an 800x500 div with four overlapping divs inside the container
I attempting to create custom tabs using this . But when I try to
I'm attempting to create a Google 2 Factor Authorisation just as an experiment not
I'm attempting to create a cascading dropdown based on the Knockout.js Cart example but
I am attempting to create some custom map routes but can't get it working
I'm attempting to create a subpage but I'm running into the error mentioned in
I am attempting to create a fixed step loop in my program, but for
When attempting to create a form with UITextFields, it appears that cellForRowAtIndexPath: gets called
I am attempting to create a database trigger capable of creating a snapshot of
I'm attempting to create an xquery expression that will return selected nodes but will

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.