Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call is not right

Status
Not open for further replies.

YoungManRiver

IS-IT--Management
Joined
Feb 9, 2004
Messages
220
Location
US
All,

I have this script, which is driving me crazy. It's a pretty simple one, just text messaging. Somehow, I'm not making the routine call right or not passing the vars.

Here is my code:
Code:
Code:
<html>
<script language="JavaScript1.2">
	function init() {
		var txtArray = new Array(5);
		var clrArray = new Array(5);
		var counter = 1;
		txtArray[0] = 'Technology';
		txtArray[1] = 'Talent'
		txtArray[2] = 'Leadership';
		txtArray[3] = 'Solutions';
		txtArray[4] = 'Savings';
		clrArray[0] = '#ffaaaa';
		clrArray[1] = '#aaaaff'
		clrArray[2] = '#aaffaa';
		clrArray[3] = '#999999';
		clrArray[4] = '#000000';
		var txa = txtArray[0]; //initial Message
		var bgc = clrArray[0]; //initial Color
//		setTimeout('init()',2000);//
		return;
	}
</script>

<BODY onload='init()'>
<table width=100% height=100% align=center valign=middle bgcolor=000000 name=target>
	<tr>
	<td align=center>
	<h1>
	<script language="JavaScript">
		var neonbasecolor="gray"
		var neontextcolor="yellow"
		var flashspeed=100
		var n=0
		var xx=0
		var txt = 'Test Message!'
		if (document.all||document.getElementById){
			document.write('<font color="'+neonbasecolor+'">')
			for (m=0;m<txt.length;m++)
			document.write('<span id="neonlight'+m+'">'+txt.charAt(m)+'</span>')
			document.write('</font>')
		} else {
			document.write(txt)
		}

		function crossref(number){
			var crossobj=document.all? eval("document.all.neonlight"+number) : 
			document.getElementById("neonlight"+number)
			return crossobj
		}

		function changeBanner() {
		 	if(counter > 4) counter = 0;
			txa = txtArray[counter];
			bgc = clrArray[counter];
			counter++;
		}

		function neon(){
			if (n==0){  //Change all letters to base color
				for (m=0;m<txt.length;m++)
				crossref(m).style.color=neonbasecolor
			}
			crossref(n).style.color=neontextcolor
//			if (yy==0) {//
//				changeBanner();//
//				txt = txa;//
//				document.target.bgcolor=bgc//
//			}//
			if (n<txt.length-1) {
				n++;
			} else {
				n=0;
				xx++;
				if (xx > 4) {
					xx=0;
					yy++;
					if (yy > 4) yy=0;
				}
				clearInterval(flashing);
				setTimeout("beginneon()",1500);
				return;
			}
		}

		function beginneon(){
			if (document.all||document.getElementById)
			flashing=setInterval("neon()",flashspeed)
		}

		beginneon()
	</script>

	</h1>
	</td>
	</tr>
</table>
The commented area is where I'm having the problem. It hangs on the first Letter and does not set the new string.

Sure hope someone know what I'm doing wrong!

YMR
 
Declare the global yy and initialize it say to 0.
[tt] [green]//var xx=0 //you existing line[/green]
var yy=0 //add this
[/tt]
 
Upon reading what I post, to disperse misunderstanding, I meant your existing line var xx=0 line to be followed by a new line of var yy=0. It did not mean to be that you have to comment out var xx=0 line, of course not.
 
Tsuji,

Tried that and no change. Did you try it?

YMR
 
I did and it functions.
 
Tsuji,

I really want all the scripting in the header area with a <div> call in the display area. I've done this is other scripts, but too green on javascript to understand the why's yet.

As for the other things, regardless of whether I move the vars outside the init function or not (even with the yy var defined), the routine always freezes at the first letter, where all letter change, one-by-one, when the section is commented out.

I think the problem is actually in the changeBanner routine. It is not actually changing the text and color assigments. I'm so limited on my knowledge that I do not know what to look at or why.

OMR
 
Changed the code to:
Code:
<html>
<script language="JavaScript1.2">
	var txtArray = new Array(5);
	var clrArray = new Array(5);
	var counter = 1;
	var neonbasecolor="gray"
	var neontextcolor="yellow"
	var flashspeed=100
	var n=0
	var xx=0
	var yy=0
	txtArray[0] = 'Technology';
	txtArray[1] = 'Talent'
	txtArray[2] = 'Leadership';
	txtArray[3] = 'Solutions';
	txtArray[4] = 'Savings';
	clrArray[0] = '#ffaaaa';
	clrArray[1] = '#aaaaff'
	clrArray[2] = '#aaffaa';
	clrArray[3] = '#999999';
	clrArray[4] = '#000000';
	var txa = txtArray[0]; //initial Message
	var bgc = clrArray[0]; //initial Color
	var txt = 'Test Message!'

	function init() {
		setTimeout('init()',2000);
		return;
	}

	function crossref(number){
		var crossobj=document.all? eval("document.all.neonlight"+number) : 
		document.getElementById("neonlight"+number)
		return crossobj
	}

	function changeBanner() {
	 	if(counter > 4) counter = 0;
		txa = txtArray[counter];
		bgc = clrArray[counter];
		counter++;
	}

	function neon(){
		if (n==0){  //Change all letters to base color
			for (m=0;m<txt.length;m++)
			crossref(m).style.color=neonbasecolor
			if (xx > 4) {
				xx=0;
				txt = txtArray[xx]
				bgc = clrArray[xx]
				document.targtb.bgcolor=bgc;
				document.write(txt)
				yy++;
				if (yy > 4) yy=0;
			}
			xx++;
		}
		crossref(n).style.color=neontextcolor
//		if (yy==0) {//
//			changeBanner();//
//			txt = txa;//
//			document.targtb.bgcolor=bgc;//
//		}//
		if (n<txt.length-1) {
			n++;
		} else {
			n=0;
			clearInterval(flashing);
			setTimeout("beginneon()",1500);
			return;
		}
	}

	function beginneon(){
		if (document.all||document.getElementById)
		flashing=setInterval("neon()",flashspeed)
	}
</script>

<BODY onload='init()'>
<table width=100% height=100% align=center valign=middle bgcolor=000000 name=targtb>
	<tr>
	<td align=center>
	<h1>
	<script language="JavaScript">
		if (document.all||document.getElementById){
			document.write('<font color="'+neonbasecolor+'">')
			for (m=0;m<txt.length;m++)
			document.write('<span id="neonlight'+m+'">'+txt.charAt(m)+'</span>')
			document.write('</font><br><font color=white>'+xx+'</font>')
		} else {
			document.write(txt+'<br><font color=white>'+xx+'</font>')
		}
		beginneon()
	</script>
	</h1>
	</td>
	</tr>
</table>
It's moving in the right direction, but not there yet.

YMR
 
On page load, init() is run. It then sets itself to run again 2000 milliseconds later. In both cases it serves no purpose. The init() function doesn't do anything else (except return).

I imagine that's part of the problem :)

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]

What is Javascript? faq216-6094
 
BJ,

Actually no. The original code works in the initial mode making the "TEST MESSAGE" change color one letter at a time.

What is being attemped it to after either an elapsed time (reason for init interval timer), or after several iterations of the coloring loop, in this case I set it to 4.

However when the "changebanner" routine is called, when the commented portion is uncommented in the original code, then the coloring freezes on the first letter.

Hope this explaination of intent helps!

YMR
 
YoungManRiver said:
More help please!

Given that you shot down Jeff's last (and correct) response ( saying that the "init" function in your most up-to-date code did nothing), have [!]you[/!] done any more work on fixing this yourself?

Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Hmmm.. I've just looked back through every single thread you've started (all 17 of them). Some stats from those:

- In only [!]1[/!] of them do you actually thank anyone for their help.

- In [!]none[/!] of them do you give any stars for the help.

- In multiple posts you quite abruptly bounce them with posts that say simply "More Help!!!!" or "Help Please!!!!!".

A bit of politeness never goes amiss, you know.

Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top