Reputation: 10779
My modal window(jquery) has one link and two buttons. On click of the link I am replacing the current view with a new view using ajax call. The new view has two button Continue
(btnContinue) and Cancel
.
The problem I am facing is the button click on the newly loaded view would not work.
My code :
$(".ddlCart li").click(function (e) {
var ddlselectedVal = $(this).attr('id');
var agentId = $("#AgentId").val();
var EnvironmentURL = $("#EnvironmentURL").val();
var Action = "PreAddToCart"
var postData = {
AgentId: agentId,
ActionTypeValue: Action
};
var close = function (event, ui) {
$(this).dialog("destroy");
}
var open = function (event, ui) {
var agentId = $("#AgentId").val();
var url = EnvironmentURL + "/Stats/SearchContacts";
$("#btncart_cancel").on("click", function () {
$('#dvModalDialog').dialog("close");
});
$("#lnkCreateNewcart").on("click", function () {
var url = EnvironmentURL + "/MLSReports/Stats/Cart";
//Send the data using post and put the results in a div
$.post(url, {
ActionTypeValue: "CreateNewContact"
},
function (data) {
// Replace current data with data from the ajax call to the div.
$("#dvModalDialog").empty().append(data);
});
});
//******* This is not firing ....
$("#btnContinue").on("click", function () {
alert('This click is from the second View');
});
};
var rd = Mod.ReportsDialog({
title: 'Add To Cart',
close: close,
open: open
});
rd.url = EnvironmentURL + "/Stats/Cart";
rd.targetElement = '#dvModalDialog'
rd.formName = '#frmCart'
rd.postData = postData
rd.open();
var $that = this;
});
Upvotes: 1
Views: 810
Reputation: 89
EDIT: 1
Let me know if this works:
$(document).on('click', '#btnContinue', function(e) {
instead of:
$("#btnContinue").click(function (e) {
Upvotes: 1
Reputation: 639
Instead of :
$(".ddlCart li").click(function (e) {
...
use this:
$(".ddlCart li").on('click', function(e){
..
Because the first function only binds to the existing html elements on the page and doesn't recognize the new ones.
Upvotes: 0