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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cannot figure out how to read the return value

    All,

    I have searched and experimented for quite some time to figure out how to read the return value from a function and have some sort of simple error that I suspect all of you will see immediately.

    I have tried to return a boolean, a string and a number to use a decision variable...

    Can one of you look at the code below and tell me what I am missing?

    (I am running this code a a workstation without any web server due to employer restrictions but I am having the same trouble on my development server ...)

    (I am trying to make a reusable function that will read the URL and let me know if it has a word in it so I can perform some logic.)

    Any help would be greatly appreciated...

    Thanks...


    <html>
    <head>
    <title> JS Test 1</title>

    <script type="text/javascript">
    function OnBodyLoadLogic(){

    // UrlHandler(); a test peice of code...

    UrlHandlerBoolean();

    if (UrlHandlerBoolean() == true) {
    alert("This has the value some URL in the URL");
    }
    else {
    alert("some is not in the URL");
    }

    }

    function UrlHandler(){
    var urlValue = (window.location.host);
    var urlValueLowerCase = urlValue.toLowerCase();

    if (urlValueLowerCase.indexOf("some URL") != -1) {
    alert("This has the value some URL in the URL");
    }
    else{
    alert("some is not in the URL");
    }
    }

    function UrlHandlerBoolean(){
    var urlValue = (window.location.host);
    var urlValueLowerCase = urlValue.toLowerCase();

    if (urlValueLowerCase.indexOf("some URL") != -1) {
    return true;
    }
    else{
    return false;
    }

    }
    function load()
    {
    alert("Page is loaded");
    }
    </script>
    </head>
    <body onload="OnBodyLoadLogic()">
    <h3> JS Return Value</h3>
    <p>
    This the beginning of the Page.
    </p>
    <div>
    A Test Div

    <span id="ReturnValueDisplay" >Initial Value</span>
    </div>

    </body>
    </html>

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    A small problem is here
    UrlHandlerBoolean();

    if (UrlHandlerBoolean() == true) {
    This will call UrlHandlerBoolean() twice but only the second call will take the return value into consideration. But nevertheless, this should work. What is the problem actually?

  • #3
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Ah - Ha! Ye Olde ~ ID-10-T error...

    Hi devnull69,

    Thanks for the quick reply... Ooopppphs-- I didn't realize that I was calling the UrlHandlerBoolean twice so that is now fixed...

    The original problem is solved because in my local workstation test I had the parentheses after the function call () in the if statement (call to the Boolean function,) but they were NOT in my server version... I saw it when I read your response and compared it to my server (and not my local desktop...)

    I still have some questions about this as a Boolean return value was the first step in my process... I will experiment a little more and write if I can't figure out the next steps...

    V/R,

    JeepGuy


  •  

    Posting Permissions

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