SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    May 2010
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript confirm (cordova)

    Hi there,

    I'm building an HTML5 app that will be deployed on iOS using Cordova. I'm trying to replace the standard "confirm" alerts with Cordova (navigator.notification.confirm), but not having much luck. My javascript skills are pretty limited, so really appreciate any advice on the code below.


    Code:
    // Delete record - Currently WORKING
    
    $(function(){
        $('#deleteRecord').click(function(e){
        	if (confirm('Do you want to delete this record?') == true) {
        		var deleteFeedSql = 'DELETE from feeds WHERE id='+feedId;
        		db.transaction(function (tx) {
            		tx.executeSql(deleteFeedSql);
            	});
        		$.mobile.changePage( "#feeds", { transition: "none"} );
        		feedId = 'undefined';
        		clearFeedDetailsScreen();
        	}
        });
    });
    
    
    
    
    // Delete record - NEW AND NOT WORKING
    $(function(){
        $('#deleteRecord').click(function(e){    	
        	navigator.notification.confirm(
            	'Do you want to delete this record?',  // message
            	onConfirmdeleteRecord,              // callback to invoke with index of button pressed
            	'Delete Record'            // title
        	);
               
        });
    });
    
    function onConfirmdeleteRecord(button) {
    //If the button has the value of '1', then do things
        if (button('1') == true) {
       		var deleteFeedSql = 'DELETE from feeds WHERE id='+feedId;
        	db.transaction(function (tx) {
           		tx.executeSql(deleteFeedSql);
           	});
       		$.mobile.changePage( "#feeds", { transition: "none"} );
       		feedId = 'undefined';
       		clearFeedDetailsScreen();
       	}
    };
    Any help much appreciated!

  2. #2
    padawan silver trophybronze trophy markbrown4's Avatar
    Join Date
    Jul 2006
    Location
    Victoria, Australia
    Posts
    4,107
    Mentioned
    28 Post(s)
    Tagged
    2 Thread(s)
    Hi,

    According to the docs the index of the button pressed is passed as a number to the callback.
    http://docs.phonegap.com/en/1.4.0/ph...cation.confirm
    Code javascript:
    if (button == 1) {
      // confirmed
    }

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2010
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Spot on - worked a charm! Thanks!!

  4. #4
    padawan silver trophybronze trophy markbrown4's Avatar
    Join Date
    Jul 2006
    Location
    Victoria, Australia
    Posts
    4,107
    Mentioned
    28 Post(s)
    Tagged
    2 Thread(s)
    No problem, I love PhoneGap.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •