I am using a function to display a dialog box that asks the users if their checks printed ok, if so, we update a flag in the database for the checks. I pass this function a "checked_id" which is a value that contains the id of the checks to update.
This code works fine the first time it runs, but when I click on another check to print "checked_id" is the same value as the previously executed id. Furthermore, the id never gets changed, unless I refresh the browser, which I don't want to have to do every time.
I have verified through firebug that the "checked_id" is actually being changed when calling the function, but something inside the jquery (im guessing) or this function is not clearing out the prevous value in the variable.
How can I fix this? Thanks in advance for any help.
Here is my js function
function confirm_print_checks_yes_no(xtitle,msg, btn_yes_txt, btn_no_txt, checked_id, xwidth, xheight)
{
var button_yes = btn_yes_txt;
var button_no = btn_no_txt;
var dialog_buttons = {};
xwidth = (xwidth) ? xwidth : 300;
xheight = (xheight) ? xheight : 150;
dialog_buttons[button_yes] = function (){ update_existing(checked_id,"xml/xml_update_db.php", "print_checks_div", "SQL_UPDATE_multiple_checks", "update_existing", "", "sql_acctg_checks.php"); $(this).dialog("close");
$(this).dialog("close");
};
dialog_buttons[button_no] = function(){$(this).dialog("close");};
$("#modal_confirm_yes_no").html(msg);
开发者_JAVA百科 $("#modal_confirm_yes_no").dialog({
title: xtitle,
bgiframe: true,
autoOpen: false,
height: xheight,
width: xwidth,
modal: true,
buttons: dialog_buttons
});
$("#modal_confirm_yes_no").dialog("open");
}
usage:
onclick="
var checked_ids = getAllCheckedIDs('my_div', 'check_print_chbx');
if(checked_ids)
{
window.open('print_checks_pdf.php?print_ids=' + checked_ids );
confirm_print_checks_yes_no(''.mysql_real_escape_string(L_PRINT_CHECKS).', ''.mysql_real_escape_string(L_PRINT_CHECKS_OK_MSG).'', ''.mysql_real_escape_string(L_PRINT_CHECKS_OK_YES_MSG).'', ''.L_NO.'', checked_ids, 500, 200 );
}
else
{
alert('No Checks Selected')
};"
If you use checked_id variable (with the sam name) also ouside of the function it might cause problems.
You can e.g. make your function return a new value of the "checked_id" and assign it to your variableoutside of the function.
For anyone who comes along I figured out that "$(this).dialog('destroy');" instead of "$(this).dialog('close'); worked.
精彩评论