JeepGuy
09-19-2011, 04: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>
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>