473,414 Members | 1,594 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Generating Frame Source by random selection

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>
  2.  
  3. <head>
  4. <title>Main Page</title>
  5. </head>
  6.  
  7. <frameset rows="100%">
  8.     <script language='javascript'>
  9. <!--
  10. var sponsorid=new Array()
  11.  
  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"
  17.  
  18. var frmSrc=sponsorid[Math.floor(Math.random()*sponsorid.length)]
  19.  
  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>
  30.  
  31. </html>
Any ideas where I'm going wrong?
Dec 16 '08 #1
5 1669
pronerd
392 Expert 256MB
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
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
acoder
16,027 Expert Mod 8TB
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
Thanks acoder! That worked perfectly!
Dec 17 '08 #5
acoder
16,027 Expert Mod 8TB
@DruidWanderer
You're welcome :)
@DruidWanderer
Glad it did! Post again if you have more questions.
Dec 17 '08 #6

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

Similar topics

1
by: Jeff Lowery | last post by:
Hi, Although I'm no Python expert, I have written generators in the past that have worked like a charm. Don't know why this one doesn't: **** class App: """ A simple Tk application that...
29
by: Bill Marsden | last post by:
Hi. I am an under-graduate currently studying Open Source (Linux) vs Closed Source and Collaboration within the IT Community. I am fairly new to Javascript and I have written a "Lottery Program"...
1
by: Intaek LIM | last post by:
generally, we use srand(time(0)) to generate random numbers. i know why we use time(0), but i can not explain how it operates. first, see example source below. ...
3
by: Evan | last post by:
I have a web page with 2 frames. The left frame is running menu.aspx and the right frame is running images.aspx. When a selection is made in menu.aspx I call a method in images.aspx and pass a...
5
by: jordi | last post by:
I need the random.sample functionality where the population grows up to long int items. Do you know how could I get this same functionality in another way? thanks in advance. Jordi
5
by: dav3 | last post by:
I have almost completed a monster assignment on sorting algorithms (quick, insertion and selection) using c++ but I am lost on one part of the assignment. I have to generate a random list of numbers...
2
by: emily224 | last post by:
Hello, I have been trying to understand this source code, which I retreived from my online course test. I would like to know how to find the answer for the question on the test. Im sure the answer...
4
by: emily224 | last post by:
Hello, I have been trying to understand this source code, which I retreived from my online course test. I would like to know how to find the answer for the question on the test. Im sure the answer...
26
by: bilgekhan | last post by:
What is the correct method for generating 2 independent random numbers? They will be compared whether they are equal. What about this method: srand(time(0)); int r1 = rand(); srand(rand());...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.