Skip to main content

how to use global variable with phonegap navigator.notification.confirm?



i have this situation:







<a href="#" onClick="submitNotification(1);">click1</a>

<a href="#" onClick="submitNotification(2);">click2</a>

<a href="#" onClick="submitNotification(3);">click3</a>



function submitNotification(cdata){

navigator.notification.confirm(

'do you like '+cdata+' option ',

submit,

'notice',

'Yes,No'

);



function submit(button){

if (button == 1){

alert(id); //or alert(cdata);

} else if (button == 2){

...

}

}







so, i click on a link, 1 or 2 ... gets send to submitNotification where i get a message: do you like 1 option or do you like 2 option or ... depending on what link i click.





this function calls submitVote and sends button var to it somehow. yes means 1 and no means 2 .





the problem is that i cant get id or cdata from the original link. actually they came as value 3 (the last link).





i use to do:







function submitNotification(cdata){

navigator.notification.confirm(

'do you like '+cdata+' option ',

submit(cdata),

'notice',

'Yes,No'

);



function submit(id){

if (button == 1){

alert(id);

} else if (button == 2){

...

}

}







in this case i get the id alert but the button values are not available.





Any ideas how to get access to that id or cdata , whatever var is available? Is there a way to send both button and cdata vars to the submit function





note: the links get created in a $.each loop.





thanks


Comments

  1. Hope this helps (after all the code rewriting :)).

    Notice that both submitNotification and submit are separate functions (not nested in) and var buttonClicked is defined in global scope.

    var buttonClicked = 0;

    function submitNotification(cdata){
    buttonClicked = cdata;

    navigator.notification.confirm(
    'do you like '+cdata+' option ',
    submit,
    'notice',
    'Yes,No'
    );
    }

    function submit(button){
    if (buttonClicked === 1){
    doWhatYouWant(); // .. but think about the Omen
    }
    }

    ReplyDelete

Post a Comment