...

View Full Version : Emulating my events



TehMadHatter
01-20-2012, 05:11 AM
I am having trouble understanding why this does not work?


<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>

Dormilich
01-20-2012, 07:56 AM
you might find the explanation in the error console.

the core problem is the value of choices, which is not what you ecpect.

TehMadHatter
01-22-2012, 11:54 PM
<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.

Dormilich
01-23-2012, 07:25 AM
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:

choices = ["http://www.google.com",
"http://www.yahoo.com",
"http://www.youtube.com",
"http://www.bing.com",
"http://www.xbox.com"];



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum