Reputation: 185
i have a dialog box and in it, it has two buttons, one that continues and one that cancels.
$(document).ready(function(){
$("[name=resetPwd]").click(function(){
var id = $(this).attr("userid");
var email = $("[field=emailAddress].[userid="+id+"]").text();
var name = $("[field=firstName].[userid="+id+"]").text();
var message = $('<div></div>')
.html('You are about to reset the password for:<br/>'+name+'.<br/>This will send an e-mail to:<br/>'+
email+'<br/><br/><input id="_continue" type="button" value="Continue" /> <input id="_cancel" type="button" value="Cancel" />')
.dialog({
title: 'Reset Password'
});
message.dialog('open');
$("#_cancel").click(function(){
message.dialog('close');
});
});
it works just fine, (the first time) all my data is there, when i click cancel, it closes, but if i try again cancel doesnt do anything anymore. does anyone know what im doing wrong? please and thanks
Upvotes: 0
Views: 556
Reputation: 5757
Try to move $("#_cancel").click
out of the $("[name=resetPwd]").click
body function. Also, you are not properly ending the $(document).ready
function.
Try this:
$(document).ready(function(){
$("[name=resetPwd]").click(function(){
var id = $(this).attr("userid");
var email = $("[field=emailAddress].[userid="+id+"]").text();
var name = $("[field=firstName].[userid="+id+"]").text();
var message = $('#message')
.html('You are about to reset the password for:<br/>'+name+'.<br/>This will send an e-mail to:<br/>'+
email+'<br/><br/><input id="_continue" type="button" value="Continue" /> <input id="_cancel" type="button" value="Cancel" />')
.dialog({
title: 'Reset Password'
});
message.dialog('open');
});
$("#_cancel").click(function(){
$('#message').dialog('close');
});
});
EDIT: Create an empty div with id=message and try the updated code.
Upvotes: 1
Reputation: 7947
You're creating a new dialog object each time you click the resetPwd element.
You should create the dialog outside of the click handler, and just reference it using open and close methods.
Upvotes: 0