Register FAQ/Rules Forum Spy Search Today's Posts Mark Forums Read

Welcome to the Mac Forums forums. Please read the FAQ if you have questions. Register to participate.

 
Go Back   Mac Forums > Special Interests > Web Design and Development
TouchArcade.com - iPhone Game Reviews and News

Reply
 
Thread Tools Search this Thread Display Modes
Old Dec 30, 2005, 11:02 PM   #1
bobber205
macrumors 68020
 
bobber205's Avatar
 
Join Date: Nov 2005
Location: Oregon
Send a message via AIM to bobber205 Send a message via Yahoo to bobber205 Send a message via Skype™ to bobber205
My ANGER at this code will never die! -- I am about to give up....

This has to be the worst code I have ever written...
It's making me SO angry.

Please, please, tell me what is wrong with this page.
The alert box continually comes up "null", which is very very incorrect.

I have look at it for an hour and a half already...
and I can't for the life of me tell what the heck is wrong.


Code:
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<title>Ticker Version 2.0</title>
<head>
<script type="text/Javascript">

var myBox = document.getElementById("tickerBox");
var tickerFrame = document.getElementById("mainDiv");
//var mytextNode = document.CreateTextNode("child this is");
//myBox.timer = setInterval(setTickerBoxText,"20");
//myBox.appendChild(textNode);




function setTickerBoxText(textValue)
{

	
		
	alert(tickerFrame);


}

</script>








<style type="text/CSS">
#mainDiv 
{
position: absolute;
top: 50px;
left: 50px;
width: 500px;
height: 400px;
background-color: rgb(201,200,100);
}
</style>
</head>

<body onLoad="setTickerBoxText('alex')">



<div id="mainDiv" onMouseOver="setTickerBoxText('a')">

</div>
http://www.alexwait.com/Nortonvillea...er/index2.html

There's the page uploaded.

Thanks for any help! I am desperate!
bobber205 is offline   Reply With Quote
Old Dec 31, 2005, 12:55 AM   #2
devman
macrumors 65816
 
devman's Avatar
 
Join Date: Apr 2004
Location: AU
disclaimer: I am NOT a web developer.

If the div hasn't been rendered at the time you try to reference it then your script (the getElementById call) will return null.

If you move the script underneath the div you will see that it is no longer null.
devman is offline   Reply With Quote
Old Dec 31, 2005, 08:22 AM   #3
belvdr
macrumors 68030
 
Join Date: Aug 2005
I'm no developer either, but I thought that this way just declared the function. Then, later in the code, you could run that function and get results at that particular moment.
belvdr is offline   Reply With Quote
Old Dec 31, 2005, 09:01 AM   #4
Mr. Anderson
Demi-God (Moderator)
 
Mr. Anderson's Avatar
 
Join Date: Nov 2001
Location: Back in VA
Send a message via AIM to Mr. Anderson
I don't have any experience with this type of code - but just looking at it you pass the text value and then you don't do anything with the text - just call

alert(tickerFrame);

Don't you want to pass the text along to the ticker frame as well?

D
__________________
"Klaatu varada nikto!"
Mr. Anderson is offline   Reply With Quote
Old Dec 31, 2005, 09:09 AM   #5
londonweb
macrumors 6502
 
Join Date: Sep 2005
Location: london
There are a few things wrong with this code.

Have you closed your <body> tag? It doesn't appear in the script here.

The first thing this tries to do is set a variable tickerFrame containing the contents of your mainDiv tag with the onLoad method, which at this point is empty, so this variable's value is set to null.

var tickerFrame = document.getElementById("mainDiv");

Then you try to call a function with the onLoad method, to display an alert with the text 'alex'. This function is called, but the alert is told to display the variable tickerFrame, which is null. If you want the alert to display 'alex', you need to let it display the contents of textValue, ie. alert(textValue).

onLoad="setTickerBoxText('alex')"

The same thing happens with the onMouseOver method.

Could you explain what it is you're trying to do? We might be able to help you do it in a better way.
londonweb is offline   Reply With Quote
Old Dec 31, 2005, 12:08 PM   #6
bobber205
Thread Starter
macrumors 68020
 
bobber205's Avatar
 
Join Date: Nov 2005
Location: Oregon
Send a message via AIM to bobber205 Send a message via Yahoo to bobber205 Send a message via Skype™ to bobber205
Thanks for all the advice.

I will do all of it.

I appreciate it greatly.
bobber205 is offline   Reply With Quote
Old Dec 31, 2005, 02:58 PM   #7
bobber205
Thread Starter
macrumors 68020
 
bobber205's Avatar
 
Join Date: Nov 2005
Location: Oregon
Send a message via AIM to bobber205 Send a message via Yahoo to bobber205 Send a message via Skype™ to bobber205
Thanks for the advice.
All of those problems are now fixed.

But, however, I've discovered an essential problem with my code.

The page is here:
http://www.alexwait.com/Nortonvillea...er/index2.html

When the mouse moves over the top green box, I have a function called "setBooleans" that takes a String variable...

If the variable is "true" I set a global variable called "shouldContinue" to true also.
This controls a while loop and prevents it from continuing on forever.

When the mouseOut event fires, I send a "false" variable to the setBooleans function and I have code in there that is supposed to set shouldContinue to false .

But it doesn't. I've added alert boxes to show me what's going on.
And that's how I found out what is wrong.

Thanks for any help.

The code in question is below.

Code:
function setBooleans(path)
{
alert("path = " + path);

if (path = "true") { 
shouldContinue = "true"; 
alert("I set it to TRUE");
}

if (path = "false") {
shouldContinue = "false";
alert("I set it to FALSE");

}
:( 
}
Again, thanks alot.
bobber205 is offline   Reply With Quote
Old Dec 31, 2005, 03:17 PM   #8
mymemory
Banned
 
mymemory's Avatar
 
Join Date: May 2001
Location: Miami
I learned today how easy my life is and how much sense it makes.
mymemory is offline   Reply With Quote
Old Dec 31, 2005, 03:26 PM   #9
bobber205
Thread Starter
macrumors 68020
 
bobber205's Avatar
 
Join Date: Nov 2005
Location: Oregon
Send a message via AIM to bobber205 Send a message via Yahoo to bobber205 Send a message via Skype™ to bobber205
Quote:
Originally Posted by mymemory
I learned today how easy my life is and how much sense it makes.


Is this spam?
Please respond with helpful comments.
bobber205 is offline   Reply With Quote
Old Jan 1, 2006, 11:58 AM   #10
londonweb
macrumors 6502
 
Join Date: Sep 2005
Location: london
I think it's because you haven't the right type of equals operators- if you want to set a variable you need to use one ie. (a = 2). If you want to find out if a is exactly equal to 2, you use two together, like this: (a == 2).

Also, I don't believe you need to use quotes when writing boolean values.

so in your case you should be writing:

if (path == true) { etc.

Try that.
londonweb is offline   Reply With Quote

Reply

Mac Forums > Special Interests > Web Design and Development

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 09:24 PM.

Mac News | Mac Rumors | iPhone Game Reviews | iPhone Apps

Powered by vBulletin® Version 3.6.10
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright 2002-2009, MacRumors.com, LLC