Solved

confirm alert error

Posted on 2010-09-22
11
426 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
 
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
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: 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how can display objects ? 3 24
JavaScript export function not working in IE 15 37
Replace &lt; with < 14 56
Error in JQuery 5 39
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
This article discusses how to create an extensible mechanism for linked drop downs.
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)
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…

895 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now