Solved

confirm alert error

Posted on 2010-09-22
11
430 Views
Last Modified: 2012-05-10
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

0
Comment
Question by:peter_coop
11 Comments
 
LVL 4

Expert Comment

by:rstjean
ID: 33734878
if(!confirm("Are you sure you wish to edit this record?")){return false;}
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33734883
replace line number 4 by

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

check for the similar cases
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 250 total points
ID: 33735157
another one :


<script language="javascript">
	function edit(com, grid) {
		if(com == 'Edit') {
			if( $('.trSelected').length>0 ) {
				if( 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.');
			}
		}
	}
</script>

Open in new window

0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 33735874
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?"); {
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33735917
@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.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 33737530
Ah, not the way his brackets were from the start
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33737638
check the number of bracket at the end
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 33737656
At the beginning:

if (com == 'Edit') {
  if($('.trSelected').length>0){
    confirm("Are you sure you wish to edit this record?");
   }
.
.
.
}
else
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33737684
At the end :

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

Author Closing Comment

by:peter_coop
ID: 33739415
thank you very much for the help.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33739603
You're welcome! Thanks for the points!
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question