Search code examples
javascriptacrobat

If statements and conditions


I am trying to confirm two different things in an alert box, if statement. The first is that the user pressed the yes button and the second is a user input value on the page. See the code below. I'm still pretty green, any help would be greatly appreciated.

var cMsg = "You are about to reset this page!";
cMsg += "\n\nDo you want to continue?";

var nRtn = app.alert(cMsg,2,2,"Question Alert Box");
if(nRtn == 4) && (getField("MV").value == 5)
{
////// do this

}
else if(nRtn == 4) && (getField("MV").value == 6)
{
/////then do this
}
else if(nRtn == 4) && (getField("MV").value == 7)
{
/////then do this
}

}
else if(nRtn == 3)
{
console.println("Abort the submit operation");
}
else
{ //Unknown Response
console.println("The Response Was somthing other than Yes/No: " + nRtn);
}

Solution

  • Your if...else syntax is incorrect. Correct syntax

    if (condition)
       statement1
    [else
       statement2]
    

    Use correct syntax

    if (nRtn == 4 && getField("MV").value == 5) {
        ////// do this    
    } else if (nRtn == 4 && getField("MV").value == 6) {
        /////then do this
    } else if (nRtn == 4 && getField("MV").value == 7) {
        /////then do this
    } else if (nRtn == 3) {
        console.println("Abort the submit operation");
    } else { //Unknown Response
        console.println("The Response Was somthing other than Yes/No: " + nRtn);
    }
    

    instead of

    if (nRtn == 4) && (getField("MV").value == 5) {
        ////// do this
    
    } else if (nRtn == 4) && (getField("MV").value == 6) {
        /////then do this
    } else if (nRtn == 4) && (getField("MV").value == 7) {
        /////then do this
    } <=== Remove this 
    
    } else if (nRtn == 3) {
        console.println("Abort the submit operation");
    } else { //Unknown Response
        console.println("The Response Was somthing other than Yes/No: " + nRtn);
    }