473,385 Members | 1,465 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,385 software developers and data experts.

roating image script not working?

ok I got this from Tom Negrino's book , "Javascript for the world wide
web 2 edition"

I downloaded it, (script 3.7) off their website
http://www.chalcedony.com/javascript.../scriptsf.html

The script is used to display a random image whenever someone enters
your website.

I adjusted the script to fit my needs. my webpage uses css and is
written in xhtml, this may be the problem, Anyhow it doesnt work. what
have I done wrong?
Thanks Melanie
<SCRIPT LANGUAGE=JAVASCRIPT>
<!-- Hide script from old browsers
// This script copyright 1997, Tom Negrino and Dori Smith.
// This script is from "JavaScript for the WWW, Visual QuickStart
Guide, 2nd Ed."
// For more information, see <http://www.chalcedony.com/javascript/>.
// This script may be used and modified, but the copyright notice
must remain intact.

var r1 = new Array(26)"http://www3.telus.net/mjw/r1/1.jpg",
"http://www3.telus.net/mjw/r1/10.jpg",
"http://www3.telus.net/mjw/r1/11.jpg",
"http://www3.telus.net/mjw/r1/2.jpg",
"http://www3.telus.net/mjw/r1/22.jpg",
"http://www3.telus.net/mjw/r1/3.jpg",
"http://www3.telus.net/mjw/r1/33.jpg",
"http://www3.telus.net/mjw/r1/4.jpg",
"http://www3.telus.net/mjw/r1/44.jpg",
"http://www3.telus.net/mjw/r1/5.jpg",
"http://www3.telus.net/mjw/r1/55.jpg",
"http://www3.telus.net/mjw/r1/6.jpg",
"http://www3.telus.net/mjw/r1/7.jpg"
"http://www3.telus.net/mjw/r1/8.jpg",
"http://www3.telus.net/mjw/r1/9.jpg",
"http://www3.telus.net/mjw/r1/dec3.jpg",
"http://www3.telus.net/mjw/r1/dp.jpg",
"http://www3.telus.net/mjw/r1/frozenwaterfall.jpg",
"http://www3.telus.net/mjw/r1/house.jpg",
"http://www3.telus.net/mjw/r1/house01.jpg",
"http://www3.telus.net/mjw/r1/imageo114.jpg",
"http://www3.telus.net/mjw/r1/pine.jpg",
"http://www3.telus.net/mjw/r1/pineriver.jpg",
"http://www3.telus.net/mjw/r1/pineriverbridge.jpg",
"http://www3.telus.net/mjw/r1/tree.jpg",
"http://www3.telus.net/mjw/r1/wf.jpg"

function choosePic() {
if (document.images) {
randomNum = Math.floor((Math.random()*10)) % 3
document.mypicture.src = r1[randomNum]
}
}

// End hiding script from old browsers -->
</SCRIPT>

<BODY BGCOLOR="WHITE" onload="choosePic()">
<IMG SRC="http://www3.telus.net/mjw/r1/dec3.jpg" WIDTH="200"
HEIGHT="135" NAME="myPicture" align="right";">
Jul 23 '05 #1
7 1468
Ivo
"melanie watts" wrote
<SCRIPT LANGUAGE=JAVASCRIPT>
Change that to

<script type="text/javascript">

You say your page is xhtml. So tags are all lowercase and attributes are all
quoted. Furthermore, there is no language attribute (anymore) and the type
is required.
<!-- Hide script from old browsers
All known browsers know to hide script contents, even if they can't execute
it. So no need for those SGML comment delimiters, it is best to remove them.
var r1 = new Array(26)"http://www3.telus.net/mjw/r1/1.jpg",
"http://www3.telus.net/mjw/r1/10.jpg",
That 's a syntax error, listing the image url's outside the array
definition. Change to

var r1 = new Array(
"http://www3.telus.net/mjw/r1/1.jpg" ,
"http://www3.telus.net/mjw/r1/10.jpg" ,
"http://www3.telus.net/mjw/r1/11.jpg" );

etc. and be careful to put comma's after each one except the last.
function choosePic() {
if (document.images) {
randomNum = Math.floor((Math.random()*10)) % 3
That 3 comes from their original script, which has just three pictures. You
may want to make it more flexible by using the array's length instead.
Something like:

var randomNum = Math.floor( Math.random() * r1.length );
document.mypicture.src = r1[randomNum]
Should probably be:

document.images.mypicture.src = r1[randomNum];
}
}


hth
--
ivo
Jul 23 '05 #2
Hi Ivo, Thanks so much for your help, however, after making all your
suggested changes it still does not work.

Melanie
Jul 23 '05 #3
Lee
melanie watts said:

Hi Ivo, Thanks so much for your help, however, after making all your
suggested changes it still does not work.

The code changes the src attribute of "mypicture",
but the actual name of your image is "myPicture".
Correct it so that they are the same.

If it still doesn't work, post your modified code.

Jul 23 '05 #4
melanie watts wrote:
ok I got this from Tom Negrino's book , "Javascript for the world wide
web 2 edition"
In addition to comments above:

[...] var r1 = new Array(26)"http://www3.telus.net/mjw/r1/1.jpg",
"http://www3.telus.net/mjw/r1/10.jpg",
There is no need to state the length of the array - it will expand to
accommodate whatever is put in it. You don't even need to use
"new Array":

var r1 = ["http://www3.telus.net/mjw/r1/1.jpg",
"http://www3.telus.net/mjw/r1/10.jpg",
...
];

<IMG SRC="http://www3.telus.net/mjw/r1/dec3.jpg" WIDTH="200"
HEIGHT="135" NAME="myPicture" align="right";">


The NAME attribute for images is only for backward compatability. ID
should be used.

There is a random ';" ' at the end of the tag that will break the HTML.

There is a missing ',' after "....7.jpg"

The "bgcolor" attribute is depreciated, use:

style="background-color: white;"

When you replace the src, all images will contine to be displayed at
200 x 135.

Loading the new image using onload means that the default image loads,
then the random. It would be better to modify the image src before the
first image loads, so only the random is shown, but keep the current
fail-over that if JS is not enabled, the default will still load.

Use the W3C HTML validator to check the HTML first (look in the left
margin menu).

<URL:http://www.w3.org/>

Below is working code, tested in Safari.
<html<head><title>images</title>
<script type="text/javascript">
var r1 = [
"http://www3.telus.net/mjw/r1/1.jpg",
"http://www3.telus.net/mjw/r1/10.jpg",
"http://www3.telus.net/mjw/r1/11.jpg",
"http://www3.telus.net/mjw/r1/2.jpg",
"http://www3.telus.net/mjw/r1/22.jpg",
"http://www3.telus.net/mjw/r1/3.jpg",
"http://www3.telus.net/mjw/r1/33.jpg",
"http://www3.telus.net/mjw/r1/4.jpg",
"http://www3.telus.net/mjw/r1/44.jpg",
"http://www3.telus.net/mjw/r1/5.jpg",
"http://www3.telus.net/mjw/r1/55.jpg",
"http://www3.telus.net/mjw/r1/6.jpg",
"http://www3.telus.net/mjw/r1/7.jpg",
"http://www3.telus.net/mjw/r1/8.jpg",
"http://www3.telus.net/mjw/r1/9.jpg",
"http://www3.telus.net/mjw/r1/dec3.jpg",
"http://www3.telus.net/mjw/r1/dp.jpg",
"http://www3.telus.net/mjw/r1/frozenwaterfall.jpg",
"http://www3.telus.net/mjw/r1/house.jpg",
"http://www3.telus.net/mjw/r1/house01.jpg",
"http://www3.telus.net/mjw/r1/imageo114.jpg",
"http://www3.telus.net/mjw/r1/pine.jpg",
"http://www3.telus.net/mjw/r1/pineriver.jpg",
"http://www3.telus.net/mjw/r1/pineriverbridge.jpg",
"http://www3.telus.net/mjw/r1/tree.jpg",
"http://www3.telus.net/mjw/r1/wf.jpg"
];

function choosePic() {
var randomNum = Math.floor( Math.random() * r1.length );
if (document.images) {
document.images('myPicture').src = r1[randomNum];
}
}
</SCRIPT>
<BODY style="background-color: white;" onload="choosePic()">
<IMG SRC="http://www3.telus.net/mjw/r1/dec3.jpg" WIDTH="200"
HEIGHT="135" id="myPicture" align="right">
</body></html>

--
Fred
Jul 23 '05 #5
Wow. Thanks. It works. Interesting that it does work in Safari and
Explorer but not Mozilla or Firefox? Wonder Why That is?

Melanie

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #6
mellly wrote:
Wow. Thanks. It works. Interesting that it does work in Safari and
Explorer but not Mozilla or Firefox? Wonder Why That is?

Melanie

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Fred Oz wrote:

(snip)
document.images('myPicture').src = r1[randomNum];


Should be:

document.images['myPicture'].src = r1[randomNum];

....as only Internet Explorer - and now apparently Safari - support
parentheses for array dereferencing.

Jul 23 '05 #7
Cool, now it working in Mozilla on my ibook. Thanks so much for your
help. I really appreaciate it.
Melanie

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #8

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

Similar topics

9
by: Karl Burrows | last post by:
I am working on a Website for a non-profit group and for some reason I have one link that doesn't want to cooperate. All the image links work fine with the onmouseover and onmouseout script except...
1
by: John Thompson | last post by:
We're sooo close. When we load the page to upload the image, all of the prms go through except the binary image data. Using SQL server with the data type set to "image". Please help! Thanks-...
8
by: jojobar | last post by:
Okay, I am trying to do is to test the webresource in 2.0 1. I created a new project with assembly name (and default assembly name) "Office". 2. I added the following to the AssemblyInfo.cs...
9
by: tshad | last post by:
Is there a way to display images (imageButtons or linkbuttons for instance) as a max size (200px by 50px) and not have it stretch the image? What I want to be able to do is limit the real estate...
9
by: tshad | last post by:
This was posted before but the message got messed up (all NLs were stripped out for some reason). I have 2 labels that hold the name of different images on my .aspx page. <asp:Label ID="Logo"...
2
by: kwenterprise | last post by:
Hello All, I am normally great at figuring out ways around iframe issues that frustrate us all. I am using javasript to try and break an iframe that I have a banner rotator embedded in but it...
4
by: MarkKM | last post by:
Hello, I'm having troubles with IE7 and the window.location function in an SVG file. This all works fine in IE6 using the Adobe SVG viewer but not in IE7, WHY? Please HELP! We use IE in Kiosk...
3
by: PrabodhanP | last post by:
I have CSS based mouseover scrolling for divContent embeded in my webpage.It works fine in IE,but not working in mozilla-FF. It is located at the location.....
9
by: neovantage | last post by:
Hey geeks, I am using a script PHP Thumbnailer which resize image at run time. But it is not working in my case as i have integrated that script by studying it's documentation. Here is the URL...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.