Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

confirm alert error

Posted on 2010-09-22
11
Medium Priority
?
434 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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:Gurvinder Pal Singh
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 1000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…
Suggested Courses

610 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