Solved

JQuery/MVC simple question creating button click through JQuery

Posted on 2013-05-14
3
1,297 Views
Last Modified: 2013-05-15
Hello all,

I have a function that inserts a button after another button.  I need the class to call a click event of the button I am creating.  The class is using a button style.  This works on another area outside of the JQuery.  So here is what I have below.  The delete-button click event function is not getting into it the way I have this.   The onEdit function actually uses a Kendo editor template that places the delete button on the editor popup.  I think it may be based on the href not being correct.   Thanks all

  function onEditCollateral(e) {
        if (e.model.isNew()) {
            updateBtnText = $(".k-grid-update").html().replace("Update", "Create");
            $(".k-grid-update").html(updateBtnText);
            return;
        }
        
        $('<a class="delete-button k-button" href="\\\#"><span class="k-icon k-delete"></span>Delete</a>').insertAfter(".k-grid-update");
    }


    $(".delete-button").click(function(e) {
        e.preventDefault();
        alert('got this');
        var kendoWindow = $("<div />").kendoWindow({
            title: "Confirm",
            resizable: false,
            modal: true
        });

        kendoWindow.data("kendoWindow")
            .content($("#delete-confirmation").html())
            .center().open();

        kendoWindow
            .find(".delete-confirm,.delete-cancel")
            .click(function() {
                if ($(this).hasClass("delete-confirm")) {
                    $('<input />').attr('type', 'hidden')
                        .attr('name', 'cmdName')
                        .attr('value', 'Delete')
                        .appendTo('#LoanForm');

                    $("#LoanForm").submit();
                }

                kendoWindow.data("kendoWindow").close();
            })
            .end();
    });

Open in new window

0
Comment
Question by:sbornstein2
  • 2
3 Comments
 
LVL 42

Accepted Solution

by:
Chris Stanyon earned 300 total points
ID: 39167648
When you bind an event using click() it will only bind the event to elements that exist when that function is called. If you then add another element dynamically, it won't have the same event binding. For this you need to use on() instead of click():

$(document).on("click", ".delete-button", function(e){
     ...
});

Open in new window

Read all about it here: http://api.jquery.com/on/
0
 

Author Comment

by:sbornstein2
ID: 39167861
this is perfect thank you.   Do you know how I can call an action method in a controller passing a parameter I have in my model.  The param is model.loanid
0
 

Author Closing Comment

by:sbornstein2
ID: 39168973
thanks
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

760 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

23 Experts available now in Live!

Get 1:1 Help Now