Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Question on Variables, Arrays, and Multiple Instances

Reply
Thread Tools

Question on Variables, Arrays, and Multiple Instances

 
 
seven
Guest
Posts: n/a
 
      01-17-2004
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.
 
Reply With Quote
 
 
 
 
Lee
Guest
Posts: n/a
 
      01-17-2004
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

 
Reply With Quote
 
 
 
 
Jim Ley
Guest
Posts: n/a
 
      01-17-2004
On 16 Jan 2004 23:12:56 -0800, Lee <(E-Mail Removed)> 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/

 
Reply With Quote
 
seven
Guest
Posts: n/a
 
      01-17-2004
On 16 Jan 2004 23:12:56 -0800, Lee <(E-Mail Removed)> 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.
 
Reply With Quote
 
Dr John Stockton
Guest
Posts: n/a
 
      01-17-2004
JRS: In article <(E-Mail Removed)>, seen in
news:comp.lang.javascript, seven <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie help- Can multiple instances with multiple namesautomatically created. Nav Python 15 01-05-2010 06:03 AM
dicts,instances,containers, slotted instances, et cetera. ocschwar@gmail.com Python 8 01-29-2009 09:52 AM
Windows multiple instances and bringing the window to the front Paul J. Lucas Java 0 11-20-2005 09:55 PM
TB multiple instances - newbie question ciqret Firefox 2 06-02-2005 10:34 PM
list of class instances within a list of a class instances John Wohlbier Python 2 02-22-2004 08:41 AM



Advertisments