0

I have a page where you can search for customers through an ajax search. In the ajax file it chucks all the results from mysql with html into a php var and passes it to JS which sticks it in a div. This part works fine.

Before the ajax was put in, I used a standard html form/php/mysql search. On each row (and still) there is a button to open a modal which is coded below.

<button class="button smsModal" id="patient301" fullname="Nathan Ironsi" phone="61425819959"><i class="fa fa-mobile"></i>&nbsp;sms</button>

Now that I am using content generated from the ajax call, this button has stopped working. I have checked the html and I have it formatted the same way as before, but the javascript is not picking up the clicks.

Could someone please explain what mistake I have made? My guess is JS doesn't like pulling html that was not a part of the original page html, but I do not know how to go about fixing this (or if it is indeed possible!)

Modal script:

$(".smsModal").on('click', function(){
    $.Dialog({
        overlay: true,
        shadow: true,
        flat: true,
        draggable: false,
        icon: '',
        title: 'SMS',
        content: '',
        padding: 24,
        onShow: function(_dialog){
            var getIdFromButton = $(event.target).attr('id');
            var getFullName = $(event.target).attr('fullname');
            var getPhone = $(event.target).attr('phone');
            var content = 'CONTENT GOES HERE';
            $.Dialog.title("Send SMS to " + getPhone);
            $.Dialog.content(content);
        }
    });
});

Thank you!

1
  • I managed to fix this by simply changing this line: $(".smsModal").on('click', function(){ to $(document.body).on('click', 'button', function(){. Yay! Commented Jun 10, 2014 at 4:38

1 Answer 1

0

I managed to fix this by simply changing this line: $(".smsModal").on('click', function(){ to $(document.body).on('click', 'button', function(){.

Thanks to Adding onClick event to dynamically generated buttons? for the answer!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.