peter_coop
asked on
confirm alert error
hello
i am trying to use a confirm alert so should the user cancel then no further action will be called. however, it is still calling the ajax call even if i click cancel. it is appearing as line 4 in the attached code. can someone show me the error? many thanks
i am trying to use a confirm alert so should the user cancel then no further action will be called. however, it is still calling the ajax call even if i click cancel. it is appearing as line 4 in the attached code. can someone show me the error? many thanks
function edit(com, grid) {
if (com == 'Edit') {
if($('.trSelected').length>0){
confirm("Are you sure you wish to edit this record?");
}
var items = $('.trSelected');
var itemlist ='';
for(i=0;i<items.length;i++){
itemlist+= items[i].id.substr(3);
}
$.ajax({
type: "POST",
dataType: "json",
url: "boxedit.php",
data: "items="+itemlist,
success: function(data){
id = data.id;
custref = data.custref;
status = data.status;
//confirm("Are you sure you wish to edit: "+data.id+"\n"+data.custref);
$.facybox({ div: '#fileeditform' });
$("#facybox").find("#id").attr({value: id });
$("#facybox").find("#custref").attr({value: custref });
$("#facybox").find("#boxref").attr({value: status });
$("#flex1").flexReload();
}
});
/*and so on then you can call facybox*/
//$("#flex1").flexReload();
} else{
alert('Please select a row to edit.');
}
}
if(!confirm("Are you sure you wish to edit this record?")){return false;}
replace line number 4 by
if ( !confirm("Are you sure you wish to edit this record?") )
{
return false;
}
check for the similar cases
if ( !confirm("Are you sure you wish to edit this record?") )
{
return false;
}
check for the similar cases
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Simpler
original:
if (com == 'Edit') { if($('.trSelected').length >0){ confirm("Are you sure you wish to edit this record?"); }
if (com == 'Edit' ) { if($('.trSelected').length >0 && confirm("Are you sure you wish to edit this record?"); {
original:
if (com == 'Edit') { if($('.trSelected').length
if (com == 'Edit' ) { if($('.trSelected').length
@mplungjan : check line 33
we've :
if($('.trSelected').length >0){
inssert row
}
else {
alert('Please select a row to edit.');
}
length>0 of but the user answer no so we get the alert : Please select a row to edit.
we've :
if($('.trSelected').length
inssert row
}
else {
alert('Please select a row to edit.');
}
length>0 of but the user answer no so we get the alert : Please select a row to edit.
Ah, not the way his brackets were from the start
check the number of bracket at the end
At the beginning:
if (com == 'Edit') {
if($('.trSelected').length >0){
confirm("Are you sure you wish to edit this record?");
}
.
.
.
}
else
if (com == 'Edit') {
if($('.trSelected').length
confirm("Are you sure you wish to edit this record?");
}
.
.
.
}
else
At the end :
else {
alert('Please select a row to edit.');
} // "else" of if($('.trSelected').length >0){
} // if (com == 'Edit') {
} // function bracket
else {
alert('Please select a row to edit.');
} // "else" of if($('.trSelected').length
} // if (com == 'Edit') {
} // function bracket
ASKER
thank you very much for the help.
You're welcome! Thanks for the points!