473,788 Members | 2,741 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.g if"
var image = images[rand1]

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

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

document.write( '<A HREF="' + link + '"target="_blan k"><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 1701
Lee
seven said:
<script language="JavaS cript">
<!-- Hide this script from old browsers -->

document.write ('<A HREF="' + link + '"target="_blan k"><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="JavaS cript">
<!-- Hide this script from old browsers -->

document.writ e('<A HREF="' + link + '"target="_blan k"><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.javas cript 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****@checkth esigline.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.g if"
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.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.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
2057
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 search php.net and have tried a dozen things I can't get to work
2
9170
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 #1, very application-like, must include the JS file for this library of functions. One reason is that it must call a function to name a "callback" function, and within its own script block, must define the callback function. The callback handles...
5
2101
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 object, is still created on the stack, I would say, so I don't understand this inline business. Apart from the fact that it is my understanding that "inline" as it exists in C++ doesn't exist in C#. Could someone please shed some light on this...
9
2027
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 used to using Arrays so I would normally do something like this: Set an array up during the init routine (called from form_load) say of
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 loaded. Will that object's value be accessible during consequent postbacks or is it set to null after HTML is rendered initially?
7
6444
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 now thown out of the array released properly by the CLI?
12
3018
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. The global variables and global functions are hidden to prevent from accessing by the programmers. All global functions share global variables. Only very few global functions are allowed to be reusability for the programmers to use. Few...
0
1151
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 point to note is that each Oracle instance requires a reasonable amount of system resouces as usually a considerable amount of memory is allocated to the instance and on UNIX there is typically half a dozen background processes hanging around just...
8
1102
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
9656
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
9499
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
10374
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
10177
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10121
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7519
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4076
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
3
2898
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.