Please Help! Alternating-Flashing-Text Script is Not working

Discussion in 'Programming' started by RogerDodgr, Feb 12, 2010.

  1. #1
    Hi, I want to be able to have two strings that alternate. I also want to be able to control the time duration that one string is visible before it is replaced by the second string.

    This does not work and is a pretty poor attempt because I keep changing my mind regarding the use of a global variable versus a return statement. (It would be nice to be able to use the function more than once on a single html page but is not necessary.)
    
    <script type="text/javascript">
    
    	alternateStrings(str1, str2, duration){
    		var str0;  //?problem if I put this variable outside the function, it is not possible to use two instances of this function. If it is inside the function, then it is not reachable for a document.write statement in the html.
    		var k = 0;
    		while(true){
    			if(k==0){str0 = str1;}
    			else{str0 = str2;}
    			setTimeout('', duration ); //???
    			
    			if(k==0){k=1;}
    			else{k=0;}
    		}
            }
    
    ...
    
    
    <script type="text/javascript">
    
         //I want to be able to have use several instances of the function. 
         //In that case, I don't think a global variable is the way to go 
         //(i.e., use the bottom example to use multiple times).
    
         //method A:
         alternateStrings(abra', 'cadabra, .5); document.write(str0);
    
         //method B:
         document.write(alternateStrings('waaaaz', 'aaaaaaa?', .25));
    </scipt>
    		
    
    Code (markup):
     
    Last edited: Feb 12, 2010
    RogerDodgr, Feb 12, 2010 IP