...

View Full Version : Cannot figure out how to read the return value



JeepGuy
09-19-2011, 05:21 PM
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>

devnull69
09-19-2011, 06:00 PM
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?

JeepGuy
09-19-2011, 06:59 PM
Hi devnull69,

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

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum