Skip to main content
Inspiring
September 21, 2011
Answered

little javascript code

  • September 21, 2011
  • 1 reply
  • 1254 views

Can someone help me with some javascript I'm having a hard time with? Below is the section I'm having a problem with. The PNR_BOM_Change_Only is a yes/no drop down, but the values are 0 and 1. The CN_Entry_Initials and Release_Status_Initials are drop downs that have a few options in them to choose from. The CN_Entry_Initials has a Null Value, C, or an N option. The Release_Status_Initials has only a U and N option. I'm trying to get this javascript to display an alert box if the PNR_BOM_Change_Only is a 1 and the CN_Entry_Initials is not equal to a C, and the Release_Status_Initials is not equal to an N. This alert box works if the PNR_BOM_Change_Only is a 1 and if I choose an N in the CN_Entry_Initials drop down and the Release_Status_Initials is a U, but it does not work if I choose an N in the CN_Entry_Initials drop down and the Release_Status_Initials is an N. This ends up processing through and it shouldn't yet because the CN_Entry_Initials is not a C. If I remove either the CN_Entry_Initials or the Release_Status_Initials code and keep the PNR_BOM_Change_Only code, this does work just fine then. What am I doing wrong?

else if(document.AddECNumber.PNR_BOM_Change_Only.value == "1" && document.AddECNumber.CN_Entry_Initials.value != "C" && document.AddECNumber.Release_Status_Initials.value != "N") { //this will return true if the input passes the regular expression

alert("ECO type required - Select (C)hange for eco line item and Select N for Release Status if PNR/BOM Change Only is yes");

}

Andy

    This topic has been closed for replies.
    Correct answer jamie61880

    Using the quotes did not work. This is what I got working with what I needed it to do:

    else if(document.AddECNumber.PNR_BOM_Change_Only.value == "1" && document.AddECNumber.CN_Entry_Initials.value != "C" && (document.AddECNumber.Release_Status_Initials.value == "U"

    || document.AddECNumber.Release_Status_Initials.value == "N")) { //this will return true if the input passes the regular expression

    alert("ECO type required - Select (C)hange for eco line item and Select N for Release Status if PNR/BOM Change Only is yes");

    }

    else if(document.AddECNumber.PNR_BOM_Change_Only.value == "1" && document.AddECNumber.CN_Entry_Initials.value == "C" && document.AddECNumber.Release_Status_Initials.value == "U") { //this will return true if the input passes the regular expression

    alert("ECO type required - Select (C)hange for eco line item and Select N for Release Status if PNR/BOM Change Only is yes");

    }

    Thanks.

    Andy

    1 reply

    Inspiring
    September 22, 2011

    Hi,

    Pls try this.

    else if(document.getElementById(PNR_BOM_Change_Only).value == "1" && document.getElementById(CN_Entry_Initials).value != "C" && document.getElementById(Release_Status_Initials).value != "N") { //this will return true if the input passes the regular expression

    alert("ECO type required - Select (C)hange for eco line item and Select N for Release Status if PNR/BOM Change Only is yes");

    }

    Note: In your file, you should be having ids as the same name like id = "PNR_BOM_Change_Only" etc.

    Inspiring
    September 22, 2011

    Meensi,

          I tried your code above and made the id's for each of the drop downs as above, but it did not work. It would not go through at all, but then I changed the update button to be a submit button rather than just a regular button. It went through, but never gave me any alert box when I didn't do it right. Any other ideas? Thanks.

    Andy

    Inspiring
    September 23, 2011

    OK, Try to break your elseif() condition and test for each condition.

    Alert the values of the dropdown, sometimes, it might be coming a True instead of 1. so check for that.

    After your submiiting a button, a form will be submitted or you will be calling a function, in that function, try to give alert for testing purpose and check for each line.

    If possible can you post your html code also??