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
My Javascript failure
Old 04-01-2009, 11:46 AM My Javascript failure
Junior Talker

Posts: 1
Trades: 0
Hi,

I am not very good at writing web pages, but the following link works in IE and also Chrome, but fails in FireFox.

http://www.broadhurst-family.co.uk/l.../Sharp1-BW.htm

If anybody is bored (!), or wants a challenge, could you tell me what I've got wrong.

The idea of the page is that one clicks on numbers and different images get downloaded.

Thank you
Chris
AncientSnapper is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-01-2009, 12:19 PM Re: My Javascript failure
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
window.event is a proprietary microsoft property, but I guess Chrome has chosen to read it. To read the last event in the window, you can pass in a parameter to the function handling the event. Also, srcElement is a Microsoft property:

Code:
function showBlend(e)
{
        e = (window.event) ? window.event : e;
        if (e.target) targ = e.target;
        else if (e.srcElement) targ = e.srcElement;

    var aa = targ.id;
    Layer = aa;
    showImage();
}
You're making this all way too complicated, though. You could just use the "this" keyword, which gives access to the event trigger automatically. Thus "this.id" would return the id, inside of the function.

Read about events: http://www.quirksmode.org/js/events_access.html
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 04-01-2009, 12:34 PM Re: My Javascript failure
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Let me show you a super-simple example as to how to do this. Your code is about 5 times too long.
JavaScript
Code:
<script type="text/javascript">
    window.onload = function() {
        var a = document.getElementById("links").getElementsByTagName("a");
        for(var i = 0; i < a.length; i++) {
            a[i].onclick = function() {
                document.getElementById("changing").src = this.href;
                return false;
            }
        }
    }
</script>
Then, in the html:
HTML Code:
<img id="changing" src="image1.jpg" />
<div id="links">
    <ul>
        <li><a href="image1.jpg">Image 1</a></li>
        <li><a href="image2.jpg">Image 2</a></li>
        <li><a href="image3.jpg">Image 3</a></li>
    </ul>
</div>
Notice that I put the image paths right into the href of the link. This way it can be read by the function. The links are wrapped with an id of "links", and the image to be switched has an id of "changing". When the anonymous function bound to links through an onclick event is finished, it returns "false", so that the browser does not follow the link. This is all that is required for a simple image switcher.
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Reply     « Reply to My Javascript failure
 

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.22743 seconds with 12 queries