By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,958 Members | 1,474 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,958 IT Pros & Developers. It's quick & easy.

Generating Frame Source by random selection

P: 3
I'm attempting to create a frame that loads a page with a specific variable based on a random number, but I can't seem to get it to work. Any help would be greatly appreciated.
Here's what I've got so far:

Expand|Select|Wrap|Line Numbers
  1. <html>
  3. <head>
  4. <title>Main Page</title>
  5. </head>
  7. <frameset rows="100%">
  8.     <script language='javascript'>
  9. <!--
  10. var sponsorid=new Array()
  12. sponsorid[0]="main.html?id=sp1"
  13. sponsorid[1]="main.html?id=sp2"
  14. sponsorid[2]="main.html?id=sp3"
  15. sponsorid[3]="main.html?id=sp4"
  16. sponsorid[4]="main.html?id=sp5"
  18. var frmSrc=sponsorid[Math.floor(Math.random()*sponsorid.length)]
  20. document.write('<frame src="'+frmSrc+'" scrolling=auto frameborder="no" border=0 noresize>');//-->
  21. </script>
  22.     <noframes>
  23.     <body>
  24. <script language='javascript'> 
  25. window.location = "main.html?id=sp1"; 
  26. </script>
  27.     </body>
  28.     </noframes>
  29. </frameset>
  31. </html>
Any ideas where I'm going wrong?
Dec 16 '08 #1
Share this Question
Share on Google+
5 Replies

Expert 100+
P: 392
You need to review proper fame tag syntax. Your JavaScript looks fine, but it will never be executed inside frame tags like this. You will have to put the JavaScript inside an HTML file called by the frame tags, or move it up and outside the frame tags.
Dec 16 '08 #2

P: 3
I'm pretty new at all this - most of that code was what I pillaged from several dissimilar scripts. Any chance you could show me how I would go about doing that?
Dec 16 '08 #3

Expert Mod 15k+
P: 16,027
Put the code in the head and instead of using document.write, put a frame container there and set its src onload.
Dec 17 '08 #4

P: 3
Thanks acoder! That worked perfectly!
Dec 17 '08 #5

Expert Mod 15k+
P: 16,027
You're welcome :)
Glad it did! Post again if you have more questions.
Dec 17 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.