Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.




349 posts

Ultimate Geek
+1 received by user: 7


Topic # 63309 24-Jun-2010 09:10
Send private message

Hi,

Any folks in here know much about Javascript?

I am wanting to link to an .js file, to keep the head of my web page im building nice and clean.  I cant figure out how to do it though.

This is what is in the <head> of my xhtml file:

[code]
<script language="javascript" type="text/javascript">
    if(document.images){
        one_off = new Image;
        one_on = new Image;
        one_off.src = "images/navigation/gallery_up.jpg"
        one_on.src = "images/navigation/gallery_down.jpg"
        two_off = new Image;
        two_on = new Image;
        two_off.src = "images/navigation/exhibitions_up.jpg"
        two_on.src = "images/navigation/exhibitions_down.jpg"
        three_off = new Image;
        three_on = new Image;
        three_off.src = "images/navigation/commissions_up.jpg"
        three_on.src = "images/navigation/commissions_down.jpg"
        four_off = new Image;
        four_on = new Image;
        four_off.src = "images/navigation/contact_up.jpg"
        four_on.src = "images/navigation/contact_down.jpg"
        }
        else{
            one_off = "";
            one_on = "";
            document.one = "";
            two_off = "";
            two_on = "";
            document.two = "";
            three_off = "";
            three_off = "";
            document.three = "";
            four_off = "";
            four_on = "";
            document.four = "";
        }
</script>
[/code]

and in the body;

[code]
<a href="gallery.html" onmouseover="document.one.src=one_on.src" onmouseout="document.one.src=one_off.src">
<img src="images/navigation/gallery_up.jpg" name ="one" alt="Gallery" width="96" height="240" border="0"/></a>
&nbsp;
<a href="exhibitions.html" onmouseover="document.two.src=two_on.src" onmouseout="document.two.src=two_off.src">
<img src="images/navigation/exhibitions_up.jpg" name="two" alt="Exhibitions" width="96" height="240" border="0"/></a>
&nbsp;
<a href="commissions.html" onmouseover="document.three.src=three_on.src" onmouseout="document.three.src=three_off.src">
<img src="images/navigation/commissions_up.jpg" name="three" alt="Commissions" width="96" height="240" border="0"/></a>
&nbsp;
<a href="contact.html" onmouseover="document.four.src=four_on.src" onmouseout="document.four.src=four_off.src">
<img src="images/navigation/contact_up.jpg" name="four" alt="Contact" width="96" height="240" border="0"/></a>[/code]

what I would like to do, is copy the script located in the head, into its own .js file ('rollover.js') and just link to it like <script language="javascript" type="text/javascript" src="rollover.js">

What would I need to change in the body, so that it still works?  I cant figure it out :(




Create new topic
Phil Gale
1107 posts

Uber Geek
+1 received by user: 44

Trusted
Red Jungle
Subscriber

  Reply # 344760 24-Jun-2010 09:12
Send private message

Sounds like you have it right to me.. just don't put the script tags into the external .js file.




Red Jungle: we make fantastic software

RSS  Twitter  Facebook  Skype



349 posts

Ultimate Geek
+1 received by user: 7


  Reply # 344766 24-Jun-2010 09:23
Send private message

I tried it out, but when I refereshed the index.html file, all the images on the page dissapeared. I thought I might need to change something in this area;
[code]
<a href="gallery.html" onmouseover="document.one.src=one_on.src" onmouseout="document.one.src=one_off.src">
<img src="images/navigation/gallery_up.jpg" name ="one" alt="Gallery" width="96" height="240" border="0"/></a>
[/code]

maybe somehow telling it to look for the 'rollover.js' file instead of just looking in the head?




 
 
 
 


1816 posts

Uber Geek
+1 received by user: 51

Trusted

  Reply # 344778 24-Jun-2010 09:43
Send private message

In the head part of the HTML page, you point to your script.
script src="http://your_script.js" type="text/javascript">
/script



349 posts

Ultimate Geek
+1 received by user: 7


  Reply # 344780 24-Jun-2010 09:46
Send private message

Oh Do'h! I didn't relise you also needed a closing tag if it was only pointing to an external file. Thanks for the help! its working now :)




Create new topic



Twitter »

Follow us to receive Twitter updates when new discussions are posted in our forums:



Follow us to receive Twitter updates when news items and blogs are posted in our frontpage:



Follow us to receive Twitter updates when tech item prices are listed in our price comparison site:





News »

Air New Zealand experiments with blockchain technology
Posted 23-Nov-2017 15:39


Symantec selects Amazon Web Services to deliver cloud security
Posted 23-Nov-2017 10:40


New Zealand Ministry of Education chooses Unisys for cloud-based education resourcing management system
Posted 22-Nov-2017 22:00


Business analytics software powers profits for NZ wine producers
Posted 22-Nov-2017 21:52


Pyrios strikes up alliance with Microsoft integrator UC Logiq
Posted 22-Nov-2017 21:51


The New Zealand IT services ecosystem - it's all digital down here
Posted 22-Nov-2017 21:49


Volvo to supply tens of thousands of autonomous drive compatible cars to Uber
Posted 22-Nov-2017 21:46


From small to medium and beyond: Navigating the ERP battlefield
Posted 21-Nov-2017 21:12


Business owners: ERP software selection starts (and finishes) with you
Posted 21-Nov-2017 21:11


Why I'm not an early adopter
Posted 21-Nov-2017 10:39


Netatmo launches smart home products in New Zealand
Posted 20-Nov-2017 20:06


Huawei Mate 10: Punchy, long battery life, artificial intelligence
Posted 20-Nov-2017 16:30


Propel launch Disney Star Wars Laser Battle Drones
Posted 19-Nov-2017 21:26


UFB killer app: Speed
Posted 17-Nov-2017 17:01


The case for RSS — MacSparky
Posted 13-Nov-2017 14:35



Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.

Alternatively, you can receive a daily email with Geekzone updates.