Solved

JQuery/MVC simple question creating button click through JQuery

Posted on 2013-05-14
3
1,326 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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 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)
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…

707 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