Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jan 2012
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Emulating my events

    I am having trouble understanding why this does not work?

    Code:
    <HTML>
    
    <HEAD>
    
    <TITLE>Event Loops</TITLE>
    
    <SCRIPT TYPE="text/javascript">
    
    function seturl(a,b,c,d,e)
    {
    	this[0] = a;
    	this[1] = b;
    	this[2] = c;
    	this[3] = d;
    	this[4] = e;
    }
    
    function selectPage(list) {
    	var page = Math.floor(Math.random()*4);
    	winow.open(list[page],"Random_Page");
    }
    
    choices = seturl("http://www.google.com,
    		 "http://www.yahoo.com,
    		 "http://www.youtube.com,
    		 "http://www.bing.com,
    		 "http://www.xbox.com");
    
    
    
    </SCRIPT>
    
    </HEAD>
    
    <BODY onLoad="selectPage(choices);">
    
    <H1>Please Wait...</H1>
    
    
    </BODY>
    
    </HTML>

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,337
    Thanks
    13
    Thanked 348 Times in 344 Posts
    you might find the explanation in the error console.

    the core problem is the value of choices, which is not what you ecpect.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #3
    New Coder
    Join Date
    Jan 2012
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <HTML>
    
    <HEAD>
    
    <TITLE>Event Loops</TITLE>
    
    <SCRIPT TYPE="text/javascript">
    
    function seturl(a,b,c,d,e)
    {
    	this[0] = a;
    	this[1] = b;
    	this[2] = c;
    	this[3] = d;
    	this[4] = e;
    }
    
    function selectPage(list) {
    	var page = Math.floor(Math.random()*4);
    	this.site = list;
    
    	 window.open(list[page],"Random_Page");
    }
    
    choices = new seturl("http://www.google.com",
    		 "http://www.yahoo.com",
    		 "http://www.youtube.com",
    		 "http://www.bing.com",
    		 "http://www.xbox.com");
    
    </SCRIPT>
    
    </HEAD>
    
    <BODY onLoad = "selectPage(choices);">
    
    <H1>Please Wait...</H1>
    
    </BODY>
    
    </HTML>

    Found it, spent like 30 mins trying to figure it out with trial and error method but happy to say I figured it out myself

    Works, thanks.

  • #4
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,337
    Thanks
    13
    Thanked 348 Times in 344 Posts
    Quote Originally Posted by TehMadHatter View Post
    Code:
    function seturl(a,b,c,d,e)
    {
    	this[0] = a;
    	this[1] = b;
    	this[2] = c;
    	this[3] = d;
    	this[4] = e;
    }
    
    //...
    
    choices = new seturl("http://www.google.com",
    		 "http://www.yahoo.com",
    		 "http://www.youtube.com",
    		 "http://www.bing.com",
    		 "http://www.xbox.com");
    you can define arrays in an easier way:
    PHP Code:
    choices = ["http://www.google.com",
             
    "http://www.yahoo.com",
             
    "http://www.youtube.com",
             
    "http://www.bing.com",
             
    "http://www.xbox.com"]; 
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •