¿Cómo usar la variable global con phonegap navigator.notification.confirm?

tengo esta situación:

<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.

esta función llama submitVote y envía button var to it somehow. yes significa 1 y no significa 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 y cdata vars to the submit función

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

gracias

preguntado el 31 de enero de 12 a las 08:01

You changed the code while I wrote an answer. Now I'll write it again to answer your question :p -

2 Respuestas

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

Note que ambos submitNotification y submit are separate functions (not nested in) and var buttonClicked se define en el ámbito global.

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
    }
}

Respondido el 31 de enero de 12 a las 12:01

yo obtengo result of expression this.setAttribute [undefined] is not a function, also in that loop i get all my links attribute, but i only need the one i clicked on - Patrioticovaca

ok, so , my loop i have this <a href="#" onClick="submitNotification('+id+');">click1</a> u think i should create a var newId = id and that will be available in my submit function? - Patrioticovaca

success, that worked, i know this is fill up text, but what does it mean? doWhatYouWant(); // .. but think about the Omen ?? is it from a quote or something? - Patrioticovaca

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

function submit(button){    
    if (button == 1){
        alert(id);
    } else if (button == 2){
        ...
    }
}

Respondido el 25 de Septiembre de 13 a las 09:09

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.