Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Need help with a script that doesn't work!
Old 07-23-2009, 02:34 AM Need help with a script that doesn't work!
Novice Talker

Posts: 11
Trades: 0
I hope i'm at the right place here. I'm new in JavaScript.
In my studies i stumbled over a code that i just can't get working.

I need to create a simple rollover effect with this JavaScript code:

JavaScript:

window.onload = rolloverInit;

function rolloverInit() {
for (var i=0; i<document.images.length; i++) {
if (document.images[i].parentNode.tagName == "A") {
setupRollover(document.images[i]);
}
}
}

function setupRollover(thisImage) {
thisImage.outImage = new Image();
thisImage.outImage.src = thisImage.src;
thisImage.onmouseout = rollOut;

thisImage.overImage = new Image();
thisImage.overImage.src = "http://www.webmaster-talk.com/images/" + thisImage.id + "_on.gif";
thisimage.onmouseover = rollOver;
}

function rollOut() {
this.src = this.outImage.src;
}

function rollOver() {
this.src = this.overImage.src;
}




HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="script11.js"></script>
<link rel="stylesheet" rev="stylesheet" href="style007.css" />

</head>
<body>

<a href="css001.html"><img src="http://www.webmaster-talk.com/images/leave01_off.gif" alt="leave01" id="leave01" /></a>
<a href="css001.html"><img src="http://www.webmaster-talk.com/images/leave02_off.gif" alt="leave02" id="leave02" /></a>

</body>
</html>




The images are in the right folder. They appear as buttons, but i don't get
the rollover effect!
I was sitting on that thing all day, but i just can't figure it out.
Where is the error?

Thanks so much for you help!

honorfield



<Fake sig link removed>
__________________
It's all happening for a reason.

Last edited by honorfield; 07-26-2009 at 08:11 PM.. Reason: Fake sig link removed
honorfield is offline
Reply With Quote
View Public Profile Visit honorfield's homepage!
 
 
Register now for full access!
Old 07-24-2009, 09:07 PM Re: Need help with a script that doesn't work!
logic ali's Avatar
Super Talker

Posts: 104
Trades: 0
Does any other script use the onload event?
This would be very simple to answer with a URL...
logic ali is offline
Reply With Quote
View Public Profile
 
Old 07-26-2009, 02:08 AM Re: Need help with a script that doesn't work!
treyk4's Avatar
Skilled Talker

Posts: 89
Name: Trey
Trades: 0
I'd reccomend installing firebug (for firefox) if you haven't already. It is THE BEST tool for debugging your scripts/webpage layout/whatever.

It will save you from so many headaches in the future.

HTH,
-Trey
treyk4 is offline
Reply With Quote
View Public Profile
 
Old 07-26-2009, 07:21 AM Re: Need help with a script that doesn't work!
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Looking at the code, you are not initialising the rollover script.

assigning your initialising function to the window.onload event does not trigger the event.
You need to call the "rolloverinit" function from the body onload event OR run it at the top of the script.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 07-26-2009, 08:03 PM Re: Need help with a script that doesn't work!
Novice Talker

Posts: 11
Trades: 0
Thanks all!

I could solve the problem with Trey's tip. I installed firebug and found a error in my script (thisimage.onmouseover = rollOver;). I had just tested the code with Dreamweaver before and it didn't show me an error!

I uploaded the test page here and it works with firefox. But Safari just shows me a rollover effect with one of the pictures.

Is it possible that the code is not up to date with some newer browser types? I got the code from an online course on lynda.com from 2008.

Cheers honorfield
__________________
It's all happening for a reason.

Last edited by honorfield; 07-26-2009 at 08:11 PM..
honorfield is offline
Reply With Quote
View Public Profile Visit honorfield's homepage!
 
Old 07-26-2009, 11:13 PM Re: Need help with a script that doesn't work!
logic ali's Avatar
Super Talker

Posts: 104
Trades: 0
Quote:
Originally Posted by honorfield View Post
I uploaded the test page here and it works with firefox. But Safari just shows me a rollover effect with one of the pictures.
Missing new operator where shown:
Quote:
Code:
thisImage.clickImage = new Image();
logic ali is offline
Reply With Quote
View Public Profile
 
Old 07-27-2009, 09:13 PM Re: Need help with a script that doesn't work!
Novice Talker

Posts: 11
Trades: 0
Cool! Thanks logic ali! That works now
__________________
It's all happening for a reason.
honorfield is offline
Reply With Quote
View Public Profile Visit honorfield's homepage!
 
Old 07-27-2009, 09:23 PM Re: Need help with a script that doesn't work!
Novice Talker

Posts: 11
Trades: 0
Hey all!
I've got another question. I'm still going through this course on lynda.com and encountered another problem that i can't solve. And it's somehow very hard to get in touch with someone there, so i hope it's alright when i post my questions here

I'm creating a form that supposed to show me my mistakes whiles filling it out, before it gets send to the server. I went through it endless times, found some errors, but it still doesn't work. Even with firebug i can't find the problem.

I uploaded the form here.

Thanks a lot for your help!!!

cheers
honorfield
__________________
It's all happening for a reason.
honorfield is offline
Reply With Quote
View Public Profile Visit honorfield's homepage!
 
Old 07-27-2009, 11:37 PM Re: Need help with a script that doesn't work!
meiamsome's Avatar
Novice Talker

Posts: 11
Trades: 0
you have your input inside a label:
'<label for="emailAddr2">Re-enter your email address:<input id="emailAddr2" type="text" size="30" class="reqd emailAddr"/>
</label>'

try
<label for="emailAddr2">Re-enter your email address:</label>
<input id="emailAddr2" type="text" size="30" class="reqd emailAddr"/>

and of corse all the others need fixing

EDIT:
in adition youve mis-spelt length:
lenghth

Last edited by meiamsome; 07-27-2009 at 11:41 PM..
meiamsome is offline
Reply With Quote
View Public Profile
 
Old 08-02-2009, 08:33 PM Re: Need help with a script that doesn't work!
Novice Talker

Posts: 11
Trades: 0
Cheers meiamsome!
It is so tricky with JavaScript to find all the little mistakes. I got to get the original script and compared with mine. The input inside the label is apparently ok, but beside the mis-spelling in "length", i could find some other miss takes as well.

How did you guys learn JavaScript?
A online-course, a book or in a class room? Can you give me any tips how to learn it the best way? Maybe some references?

Thanks a lot for your help

honorfield
__________________
It's all happening for a reason.
honorfield is offline
Reply With Quote
View Public Profile Visit honorfield's homepage!
 
Reply     « Reply to Need help with a script that doesn't work!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.31163 seconds with 12 queries