Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with coding

    Hello, first time posting on forum, hope you guys can help me with this problem I have.

    I'm basically trying to get the value from a div tag and compare it to something else, like "05:10:50" and, if they are the same I want it to run something else.
    The value in the div tag is dynamic and always changes. That's why I want it to run another piece of code once it has matched "05:10:50".

    Code for getting the value.
    Code:
    document.getElementById('divid').innerHTML;
    I am completely stumpped as to how to do this but I know it'll involve "if...else" and "while".

    Thanks....

  • #2
    New Coder
    Join Date
    May 2009
    Posts
    55
    Thanks
    1
    Thanked 4 Times in 4 Posts
    It's important to identify that the first child is the text. For more take a look at

    http://slayeroffice.com/articles/inn..._alternatives/

    And especially the [2a] Getting the Text Value of an Element part

  • #3
    New to the CF scene
    Join Date
    May 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for that bit of info.

    Ok so I have this now, which works perfectly, but I now need it automated.
    Code:
    counter = document.getElementById("divid").firstChild.nodeValue;
    target = "00:50:10";
    if (counter == target)
    {
    "Found";
    }
    else
    {
    "Waiting";
    }
    I was wondering how you would go about looping through all this (as my target is dynamic) but also having a time interval between each loop because it will crash.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,731
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Code:
    <body onload = "checkTarget()">
    
    <script type = "text/javascript">
    
    target = "05:50:10";
    function checkTarget() {
    counter = document.getElementById("divid").firstChild.nodeValue;
    if (counter == target) {
    doSomethingElse();  // call another function
    return false;
    }
    window.setTimeOut("checkTarget()", 2000);  // check every two seconds
    
    </script>

    Do please read the posting guidelines regarding thread titles. The thread title is supposed to help people who have a similar problem in future. Yours is useless for this purpose. You can edit it to someting more meaningful.
    Last edited by Philip M; 05-09-2009 at 08:37 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •