Solved

JQuery/MVC simple question creating button click through JQuery

Posted on 2013-05-14
3
1,306 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 43

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Hi all! Recently there was EE question and the person wanted to have a multi-column textbox <div> selection, so as a first step to answer I provided a link but that was not complete with JavaScript selection, but had a good style sheet. So as a ques…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

770 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