Solved

jQuery code does not fire on modal forms

Posted on 2014-03-20
3
431 Views
Last Modified: 2014-03-21
I have a simple link that will fire an ajax call and change a status, and I want that new status reflected (instantly) on the modal form.

Problem is: when I click the link that is on the modal form (below), nothing happens.

    <a title="Autoplay" data-placement="top" data-toggle="tooltip" class="glyphicon glyphicon-stop" id="autoplayStatus" href="#"></a>

Open in new window


In $(document).ready(), I have this:
    $("#autoplayStatus").click(function(event){
            alert('test');
        })

Open in new window


Is there something I should do to ensure that jQuery can select and bind to objects on a modal form?
0
Comment
Question by:DrDamnit
  • 2
3 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
Comment Utility
Change this
    $("#autoplayStatus").click(function(event){
            alert('test');
        })

Open in new window

to
    $(document).on("click","#autoplayStatus",function(event){
            alert('test');
        })

Open in new window

0
 
LVL 32

Author Comment

by:DrDamnit
Comment Utility
Follow up:
The code works, but I have two elements (checkboxes) in the div. I have used the class / container function so I only have to write one function to manage these, but each of the checkboxes carries with them a data attribute that is requried for an ajax call. $(this) no longer refers to the checkbox clicked, but rather the div. How do I refer to the checkbox that was clicked (specifically) so I can extract that id from the data attribute?
0
 
LVL 58

Expert Comment

by:Gary
Comment Utility
Inside the click event use $(this) to target the actual clicked checkbox
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now