473,769 Members | 7,097 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Generating Frame Source by random selection

3 New Member
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 1685
pronerd
392 Recognized Expert Contributor
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
DruidWanderer
3 New Member
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 Recognized Expert Moderator MVP
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
DruidWanderer
3 New Member
Thanks acoder! That worked perfectly!
Dec 17 '08 #5
acoder
16,027 Recognized Expert Moderator MVP
@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
1378
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 plots random lines
29
2285
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" which essentially picks 6 numbers at random and puts them in sequence. Would anyone would be interested in modifying the code below to a). Check for bugs b). Make the program more efficient
1
30933
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. --------------------------------------------- #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv)
3
2724
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 variable. The intention is that images.aspx will take the variable and load images into its frame (the right one) based on the variable passed. What actually happens is the method runs in the left frame and ruturns the error "Object reference not...
5
2279
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
5726
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 in reverse order as follows "list = 25.88 - sqrt(i)" and perform all my sorting functions no this list. I have successfully run my program on numerous lists of random numbers.. I just have no clue how to get a reverse generated list of random...
2
5088
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 must be embedded somewhere in the source code, and I would like to know if anyone knows where to find the correct answer. I would greatly appreciate it!! Thanks!! <!--put the preloads file here as it must load before the website class...
4
68268
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 must be embedded somewhere in the source code, and I would like to know if anyone knows where to find the correct answer. I would greatly appreciate it!! Thanks!!
26
7915
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()); int r2 = rand(); bool f = r1 == r2;
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10214
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9865
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5304
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3963
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.