for(i in XDocument) - not works - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

for(i in XDocument) - not works

Last post 11-25-2006 11:10 AM by TTS. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 11-22-2006 03:42 PM

    • TTS
    • Not Ranked
    • Joined on 11-22-2006
    • Posts 9

    for(i in XDocument) - not works

    How to find object with property having specified value?
    This code doesn't work
    function findPropertyByValue(needle, fObj)
    {
    var i;
    for(i in fObj){
    if(fObj==needle) return i;
    }

    var success;
    if(fObj.firstChild!=null){
    success=findPropertyByValue(needle, fObj.firstChild);
    if(success!=null) return "->"+success;
    }
    while(fObj.nextSibling!=null){
    success=findPropertyByValue(needle, fObj=fObj.nextSibling);
    if(success!=null) return "->"+success;
    }
    return null;
    }


    function CTRL21_7::OnClick(eventObj)
    {
    var dest=findPropertyByValue("something", XDocument.DOM);
    if(dest!=null) XDocument.UI.Alert(dest);
    }

    There is error on row "for(i in fObj){" (object doesn't support command)
    What's wrong? How to do it?
  • 11-22-2006 09:38 PM In reply to

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

    Re: for(i in XDocument) - not works

    Hi TTS welcome to the Forums,

    We don't have syntax like "for(i in fObj)". We need to use "foreach(i in fObj)" otherwise you can use directly for loop.
    If you want to get more information on loops go through this link,
    http://www.samspublishing.com/articles/article.asp?p=101656&seqNum=6&rl=1
  • 11-23-2006 04:02 AM In reply to

    • TTS
    • Not Ranked
    • Joined on 11-22-2006
    • Posts 9

    Re: for(i in XDocument) - not works

    Thanks, but it's js, not c# script
    Did I posted this in wrong forum?
  • 11-23-2006 06:33 AM In reply to

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

    Re: for(i in XDocument) - not works

    Hi TTS,

    I am sorry. In C#, we will used to 'foreach' loop but in JScript your syntax is correct. Can you check once 'fObj' object is get the value or not. And one more is what about 'needle' value?

    You can get the more information on 'for' and 'for in' loops
    http://msdn2.microsoft.com/en-gb/library/y3wd7kkh.aspx
  • 11-24-2006 11:20 AM In reply to

    Re: for(i in XDocument) - not works

    Hi,
    XDocument.DOM in var dest=findPropertyByValue("something", XDocument.DOM); is just one node, its not an enumerator to loop through it.
    Probably you want to loop through the children of "XDocument.DOM".
  • 11-25-2006 11:10 AM In reply to

    • TTS
    • Not Ranked
    • Joined on 11-22-2006
    • Posts 9

    Re: for(i in XDocument) - not works

    Of course I want loop through the chidren, but that's not the explanation.
    I found that for...in works fine with objects made by script itself such as
    obj={"a" : "Athens" , "b" : "Belgrade", "c" : "Cairo"}
    but not with
    XDocument, XDocument.DOM.firstChild, eventObj and so on.
    It's a pity.
Page 1 of 1 (6 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.