Link to home
Start Free TrialLog in
Avatar of peter_coop
peter_coopFlag for United Kingdom of Great Britain and Northern Ireland

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
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.');
        }
    }

Open in new window

Avatar of rstjean
rstjean
Flag of Canada image

if(!confirm("Are you sure you wish to edit this record?")){return false;}
Avatar of Gurvinder Pal Singh
replace line number 4 by

if ( !confirm("Are you sure you wish to edit this record?") )
{
  return false;
}

check for the similar cases
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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?"); {
@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.
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
At the end :

                  else {
                        alert('Please select a row to edit.');
                  } // "else" of if($('.trSelected').length>0){
            } // if (com == 'Edit') {
      } // function bracket
Avatar of peter_coop

ASKER

thank you very much for the help.
You're welcome! Thanks for the points!