...

View Full Version : Assigning parameters for functions, and looping



glo_worm28
06-27-2006, 06:53 PM
I am a beginner of JavaScript, and am trying to work out a code through which the following action can take place:
There is a frame, the top part of the frame contains a button. On clicking the button, the bottom part of the frame changes colors, which are contained in an array present in the head of the code.
For some reason, this is not working, perhaps something wrong with the way I have assigned the parameters.
Can anybody help?
Here is the required part of the code:

<html>
<head>
<script language="Javascript">
<!--
var colory = new Array ("red","blue","green","yellow","orange");
var loop ="";

function fixLoopy()
{

for(var loop = 0; loop<colory.length; loop+=1)

for (var loop = 0; loop > colory.length; loop = 0)
{ return loop;
}

}
//-->
</script>

</head>

And in the body section,

<a href="#" onClick="fixLoopy(); top.bottom_target.document.bgColor= colory[loop]; return false;">
<img src="rainbow.jpg" width="46" height="40"> </a>

Mr J
06-27-2006, 07:40 PM
Try it this way


<HTML>
<HEAD>
<TITLE>Document Title</TITLE>

<script language="Javascript">
<!--
var colory = new Array ("red","blue","green","yellow","orange");

var loop =0

function fixLoopy(){

parent.bottom_target.document.body.style.backgroundColor=colory[loop]

loop++

if(loop==colory.length){
loop=0
}

setTimeout("fixLoopy()",1000)
}

//-->
</script>

</HEAD>
<BODY>

<a href="#" onClick="fixLoopy(); return false">
<img src="rainbow.jpg" width="46" height="40"> </a>
</BODY>
</HTML>

glo_worm28
06-28-2006, 05:17 AM
thanks so much! it was succesful!! i just had to remove the "timeout" line because i just wanted the colour to change one-by-one on clicking... anyway thanks a lot :-)

Kor
07-14-2006, 11:53 PM
a little bit shorter:


<script type="text/javascript">
var colory = ['red','blue','green','yellow','orange'];
var loop=0;
function fixLoopy(){
loop=loop==colory.length?0:loop;
parent.bottom_target.document.body.style.backgroundColor=colory[loop];
loop++;
}
</script>



<img src="rainbow.jpg" width="46" height="40" onclick="fixLoopy()" style="cursor:pointer">



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum