473,503 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question on Variables, Arrays, and Multiple Instances

This might be a newbie question or otherwise easy stuff for some of
you, but it's tweaking me ... can't seem to get it to work right.

I am working with a script that basically creates two arrays, and with
a single call in the html, randomly inserts a graphic (which is linked
to another page, as defined in the second array). The working example
is
http://seven.postmodern.com/insight/...rdreading.html

What I would like to do is call multiple instances of random images,
but the way I have it currently set up, I get the same random image if
I try to call it more than once - so I've tried defining additional
variables but perhaps I am doing it incorrectly. Can anyone help or
offer a tip/tutorial on this if possible? I can workaround by using a
frameset but that gets ugly if doing too many cards. help?

var imagenumber = 44 ;
var randomnumber = Math.random() ;
var rand1 = Math.round( (imagenumber-1) * randomnumber) + 1 ;
images = new Array
images[1] = "image1.gif"
images[2] = "image2.gif"
....
images[44] = "image22r.gif"
var image = images[rand1]

links = new Array
links[1] = "image1.htm"
links[2] = "image2.htm"
....
links[44] = "image22r.htm"
var link = links[rand1]

/then it within the page, calls the graphic as such
<script language="JavaScript">
<!-- Hide this script from old browsers -->

document.write('<A HREF="' + link + '"target="_blank"><IMG SRC="' +
image + '" border="0"></a>')
<!-- End Hiding Here -->
</script>
---
http://seven.postmodern.com
seven at post modern dot com
If sending an email, +add+ the word "newsgroup" to the subject line to temporarily work around my spam block utility.
Jul 20 '05 #1
4 1673
Lee
seven said:
<script language="JavaScript">
<!-- Hide this script from old browsers -->

document.write('<A HREF="' + link + '"target="_blank"><IMG SRC="' +
image + '" border="0"></a>')
<!-- End Hiding Here -->
</script>

I love the superstitious "hiding from old browsers", done
in a way that wouldn't hide anything from any browser.

Thanks

Jul 20 '05 #2
On 16 Jan 2004 23:12:56 -0800, Lee <RE**************@cox.net> wrote:
seven said:
<script language="JavaScript">
<!-- Hide this script from old browsers -->

document.write('<A HREF="' + link + '"target="_blank"><IMG SRC="' +
image + '" border="0"></a>')
<!-- End Hiding Here -->
</script>

I love the superstitious "hiding from old browsers", done
in a way that wouldn't hide anything from any browser.


but at least it would work in an XHTML browser!

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #3
On 16 Jan 2004 23:12:56 -0800, Lee <RE**************@cox.net> wrote:

I love the superstitious "hiding from old browsers", done
in a way that wouldn't hide anything from any browser.


I know, holdovers that don't do anything....

Any ideas on the variable control?
---
http://seven.postmodern.com
seven at post modern dot com
If sending an email, +add+ the word
"newsgroup" to the subject line to
temporarily avert the spam filter.
Jul 20 '05 #4
JRS: In article <oo********************************@4ax.com>, seen in
news:comp.lang.javascript, seven <no****@checkthesigline.com> posted at
Sat, 17 Jan 2004 06:47:36 :-

What I would like to do is call multiple instances of random images,
but the way I have it currently set up, I get the same random image if
I try to call it more than once - so I've tried defining additional
variables but perhaps I am doing it incorrectly. Can anyone help or
offer a tip/tutorial on this if possible? I can workaround by using a
frameset but that gets ugly if doing too many cards. help?
Read the c.l.j FAQ.

If your images repeat, it is probably because the names repeat. Cut out
image-fetching and show the names.

If your names repeat, it is probably because the indexes repeat. Cut
out name look-up and show the indexes.

Always simplify a problem until it becomes obvious where the trouble is.
var imagenumber = 44 ;
var randomnumber = Math.random() ;
var rand1 = Math.round( (imagenumber-1) * randomnumber) + 1 ;
Generates unevenly distributed numbers; see c.l.j FAQ.
images = new Array
Your images is the name of an existing part of the document; use a
different identifier such as imgs
images[1] = "image1.gif"
images[2] = "image2.gif"
...
images[44] = "image22r.gif"
It is silly to test with 44 elements when failures occur. Test with,
say, 4.

---

DSS.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2022
by: chad phillips | last post by:
Hi, (Newbie to php). I am trying to read in a list of ids. Here is my url http://localhost/a.php?id=1&id=2&id=3 Then I just want to print out the ids, but I can't seem to get it work. I...
2
9137
by: Patient Guy | last post by:
I have a library of functions representing a filesystem interface (essentially a file selection interface, to be used in opening/reading/writing/closing files). Heavily scripted HTML document...
5
2074
by: Zach | last post by:
When it is being said that, "value types are created on the stack or inline as part of an object". If a value type is created in an object, and that object is being called, the value type in that...
9
2007
by: me | last post by:
Hi All, I am new to Classes and learniing the ropes with VB.NET express Here's my question - say I have a want to manage a list of books. Each book has an Author, Title and ISBN Now, I am...
4
343
by: Diffident | last post by:
Hello All, I have a question which is pertinent to Page's lifecycle. I declared a protected static object (global variable within that class) whose value is set only once when the page is...
7
6409
by: heddy | last post by:
I have an array of objects. When I use Array.Resize<T>(ref Object,int Newsize); and the newsize is smaller then what the array was previously, are the resources allocated to the objects that are...
12
2994
by: Bryan Parkoff | last post by:
I write my large project in C++ source code. My C++ source code contains approximate four thousand small functions. Most of them are inline. I define variables and functions in the global scope....
0
1136
by: Chris O | last post by:
"Larry Lowe" <llowejr@usa.netwrote in message news:ad17577.0308140714.1b14d778@posting.google.com... Hi Larry. Some responses aren't very helpful. I'll try to do a little better. The first...
8
1093
by: Magnus.Moraberg | last post by:
Hi, Lets say I have a class called Point and I give this class the following properties - int CoordinatesInPixels{...} float CoordinatesInInches{...} And the Method -
0
7192
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,...
0
7064
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
7315
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6974
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7445
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
4665
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...
0
1492
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 ...
1
721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
369
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...

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.