Newbie need help on js

This is a discussion on "Newbie need help on js" within the JavaScript Forum section. This forum, and the thread "Newbie need help on js are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Nov 30th, 2007, 12:48
Junior Member
Join Date: Nov 2007
Location: Hong Kong
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Newbie need help on js

i am trying to "rotate" 4 images at set time interval

here's my javascript
Code: Select all
window.onload = newpage;
var i=0;

function newpage() {
    var x = window.outerWidth - window.innerWidth + 905; 
    var y = window.outerHeight - window.innerHeight + 454;
    window.resizeTo(x, y);
    if (document.getElementById){;}
    else {alert ("Sorry, your browser doesn't support this script");}

    rotateImg;
}

function rotateImg(){
    switch (i){
    case 0: document.getElementById.("img1").src='../miniproject/images/icon_broadcaster.gif';
            document.getElementById.("img2").src='../miniproject/images/Devices_Icon.png';
            document.getElementById.("img3").src='../miniproject/images/burn_icon.png';
            document.getElementById.("img4").src='../miniproject/images/icon_streamingserver.gif'; break;
    case 1: document.getElementById.("img1").src='../miniproject/images/icon_streamingserver.gif';
            document.getElementById.("img2").src='../miniproject/images/icon_broadcaster.gif';
            document.getElementById.("img3").src='../miniproject/images/Devices_Icon.png';
            document.getElementById.("img4").src='../miniproject/images/burn_icon.png'; break;
    case 2: document.getElementById.("img1").src='../miniproject/images/burn_icon.png';
            document.getElementById.("img2").src='../miniproject/images/icon_streamingserver.gif';
            document.getElementById.("img3").src='../miniproject/images/icon_broadcaster.gif';
            document.getElementById.("img4").src='../miniproject/images/Devices_Icon.png'; break;
    case 3: document.getElementById.("img1").src='../miniproject/images/Devices_Icon.png';
            document.getElementById.("img2").src='../miniproject/images/icon_streamingserver.gif';
            document.getElementById.("img3").src='../miniproject/images/burn_icon.png';
            document.getElementById.("img4").src='../miniproject/images/icon_broadcaster.gif'; break;
    }
    i++;
    if (i==4){
    i=0;}
    setInterval("rotateImg()",3000);
}
And this is the section of html where i put my images

Code: Select all
<div id="rightcol">
    <a href="registration.htm" ><img id="img1" alt="User Registration" src="../miniproject/images/Devices_Icon.png"/></a>
    <a href="clipbrowser.htm" ><img id="img2" alt="Browse Audio Clip" src="../miniproject/images/Devices_Icon.png"/></a>
    <br />
    <img id="img3" src="../miniproject/images/Devices_Icon.png" alt="_" />
    <a href="audioplayer.htm" ><img id="img4" alt="Audio Player" src="../miniproject/images/Devices_Icon.png"/></a>
</div>
my script isn't working
can anyone tell me what's wrong?

thanks!!

Last edited by Rakuli; Nov 30th, 2007 at 12:53. Reason: adding [code][/code] around scripts makes it easier to read
Reply With Quote

  #2 (permalink)  
Old Nov 30th, 2007, 12:53
Junior Member
Join Date: Nov 2007
Location: Hong Kong
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Newbie need help on js

PS i have a question concerning DOM
whats the difference between window.document.getElementById.... and document.getElementById...?


thx
Reply With Quote
  #3 (permalink)  
Old Nov 30th, 2007, 12:55
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Newbie need help on js

you have a random semi-colon in the first function of your script that may be cascading to errors further down, fix that first.

Code: Select all
   if (document.getElementById){;}
Can you explain if there is a specific error given by your browser as well?

Thanks.
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
  #4 (permalink)  
Old Nov 30th, 2007, 12:57
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Newbie need help on js

In regards to your second question, there is now difference,

document.getElementById is the same as window.getElementById however, you may wish to refer to a specific window and sometimes you can get lost so if you opened a popup named "thisPopup" and want to reference it from the opening window use

thisPopup.document.getElementById.

Essentially, placing window. in front of the your document calls means that javascript cannot possibly falsely choose the scope as you you are telling it to explicity reference "THIS" window...

Hope that makes sense,
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
  #5 (permalink)  
Old Nov 30th, 2007, 13:07
Junior Member
Join Date: Nov 2007
Location: Hong Kong
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Newbie need help on js

Thanks for the quick reply!

i've deleted the lines of if and else in the newpage function
yet nothing happens... and no my browser did not give any error message
images simply did not change
Reply With Quote
  #6 (permalink)  
Old Nov 30th, 2007, 13:16
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Newbie need help on js

rotateImg;

needs to have parenthesis you tell javascript it is a function call

Code: Select all
function newpage() {
    var x = window.outerWidth - window.innerWidth + 905; 
    var y = window.outerHeight - window.innerHeight + 454;
    window.resizeTo(x, y);
    if (document.getElementById){;}
    else {alert ("Sorry, your browser doesn't support this script");}

    rotateImg();
}
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
  #7 (permalink)  
Old Nov 30th, 2007, 14:12
Junior Member
Join Date: Nov 2007
Location: Hong Kong
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Newbie need help on js

hmmmm still it isn't working
anyway thx!
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 On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hello everyone! Another newbie here. Joker Introduce Yourself 6 Aug 19th, 2007 20:52
newbie Janna122003 Introduce Yourself 7 Feb 6th, 2007 17:21
Hi newbie to all! Brooksy Introduce Yourself 3 Dec 7th, 2006 22:24
Newbie toefunky Introduce Yourself 6 Nov 19th, 2006 05:54
help with css for a newbie sing2trees Web Page Design 2 Jan 29th, 2006 16:24


All times are GMT. The time now is 10:41.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43