What's wrong with this if else statement? - InfoPath Dev
in

InfoPath Dev

What's wrong with this if else statement?

Last post 09-26-2006 05:31 PM by cornik99. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 09-15-2006 05:09 PM

    What's wrong with this if else statement?

    Codes run okay when sourcePhDirect <> null but when it's blank the value of sourceExt is being returned as null even though it has a value. This for the business card order form where the phone value is fill-in from another form using the direct line number but if an employee doesn't have one then it's the company main number plus the extension.


    var sourcePhDirect = XDocument.DOM.selectSingleNode("//my:myFields/my:telephone_direct");
    var sourceExt = XDocument.DOM.selectSingleNode("//my:myFields/my:telephone_ext");

    if (sourcePhDirect != null)
    destPhone.text = XDocument.DOM.selectSingleNode("//my:myFields/my:telephone_direct").text;
    else
    destPhone.text = "(555)-201-8000 x" + XDocument.DOM.selectSingleNode("//my:myFields/my:telephone_ext").text;
  • 09-20-2006 12:09 AM In reply to

    Re: What's wrong with this if else statement?

    Can you try (sourcePhDirect != "") instead of if (sourcePhDirect != null).
    Listen to Motörhead cos they play Rock'n Roll :)
  • 09-21-2006 12:26 AM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: What's wrong with this if else statement?

    Hi Cornik,

    Can you try for one more condition,

    if (sourcePhDirect != undefined)
  • 09-21-2006 12:35 AM In reply to

    Re: What's wrong with this if else statement?

    And please let us know what resolved your issue.
    Listen to Motörhead cos they play Rock'n Roll :)
  • 09-21-2006 10:10 AM In reply to

    Re: What's wrong with this if else statement?

    Checking for null is correct assuming that you expect the node to be physically not present in the DOM at times. If you want to know whether it is blank... that's different.

    Also, you don't need to reselect the field multiple times as you've already stored it in a variable.

    Try:

    1. For node to be physically not present:

    var sourcePhDirect = XDocument.DOM.selectSingleNode("//my:myFields/my:telephone_direct");
    var sourceExt = XDocument.DOM.selectSingleNode("//my:myFields/my:telephone_ext");

    if(sourcePhDirect != null)
        destPhone.text = sourcePhDirect.text;
    else
        destPhone.text = "(555)-201-8000 x" + sourceExt.text;


    2. For node value being blank:

    var sourcePhDirect = XDocument.DOM.selectSingleNode("//my:myFields/my:telephone_direct");
    var sourceExt = XDocument.DOM.selectSingleNode("//my:myFields/my:telephone_ext");

    if(sourcePhDirect.text != "")
        destPhone.text = sourcePhDirect.text;
    else
        destPhone.text = "(555)-201-8000 x" + sourceExt.text;


    3. For node being either not present or blank:

    var sourcePhDirect = XDocument.DOM.selectSingleNode("//my:myFields/my:telephone_direct");
    var sourceExt = XDocument.DOM.selectSingleNode("//my:myFields/my:telephone_ext");

    if(sourcePhDirect.text != null && sourcePhDirect.text != "")
        destPhone.text = sourcePhDirect.text;
    else
        destPhone.text = "(555)-201-8000 x" + sourceExt.text;
  • 09-26-2006 05:09 PM In reply to

    Re: What's wrong with this if else statement?

    Thank you all for your help but the one that worked was Greg's solution #3 (For node being either not present or blank). Greg, you're great! Sorry, I was sick so I wasn't able to respond right away.
  • 09-26-2006 05:31 PM In reply to

    Re: What's wrong with this if else statement?

    I have another issue with if else on opening another form which I started on new thread .open another form using if else condition'. So, please help me again. Thanks.
Page 1 of 1 (7 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.