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.

// 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!

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/phonegap_notification_notification.md.html#notification.confirm


if (button == 1) {
  // confirmed
}

Spot on - worked a charm! Thanks!!

No problem, I love PhoneGap.