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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Randomization 1

Status
Not open for further replies.

soonkhoo

Programmer
Dec 8, 2000
133
MY
Hi,

How do I randomize so that Page1 will include

<script language=&quot;Javascript&quot; src=&quot;test1.js&quot;></script>, then when refreshed or enter again,

Page1 will replace that js file to test2.js in a random order?

Thanks

skhoo
 
hi soonkhoo,
may be smth like this?
<script>
var ii=Math.floor(Math.random()*10)
var string
switch (ii){
case 0:{ string='file0.js' ; break}
case 1:{ string='file1.js' ; break}
case 2:{ string='file2.js' ; break}
case 3:{ string='file3.js' ; break}
case 4:{ string='file4.js' ; break}
case 5:{ string='file5.js' ; break}
case 6:{ string='file6.js' ; break}
case 7:{ string='file7.js' ; break}
case 8:{ string='file8.js' ; break}
case 9:{ string='file9.js' ; break}
default : break
}
document.write('<'+'script language=&quot;javascript&quot; src=&quot;'+string+'&quot;>'+'</'+'script>')
</script>


regards, vic
 
Thanks!! But can you explain to me how do you call the script or run it for there's no function. Does that mean I need to insert it in the body tag? Thanks. :)

skhoo
 
hi again
it's just a example, but it does what u want 2 do (at least it includes dfrnt js files randomly)
it is advised 2 place scripts into head section, then it wuld include file just in the process of page generation;
'coz if u wuld make a function with such code & call it whenever after page have been generated - document.write wuld overwrite the hole page, & ur document wuld be gone..

regards, vic
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top