C# Web and .js - where and how do I specify the location of the .js file

I have a very basic web site I am deploying (dev site is http://ct1data.utrackit.net) and there are a few functions that control the displaying of sub-information.
For example: on the products page there is a line of code:
<li><a href="javascript:showguide(1);">Introduction &raquo;</a></li>

"showguide" is defined in a file "functions.js" as:
function showguide(id){
      for (x=1;x<=5;x++){
            closeid = "section" + x;
            document.getElementById(closeid).style.display="none";
      }
      openid = "section" + id;
      document.getElementById(openid).style.display="block";
      }

Now the problem is the "showguide" function only works if the file "functions.js" is in the root (i.e. the same folder as the page calling it). I want the .js files to all be in the /scripts folder!

Where in the project (or in the .aspx file) do I tell it the .js file is in /scripts?
Bird757Asked:
Who is Participating?
 
käµfm³d 👽Connect With a Mentor Commented:
No. That's my fault for not being clearer.

You need to put it somewhere within the <html> tag. Common practice is to put it within the <head> tag, though it should work anywhere within the <html> tag.
0
 
käµfm³d 👽Commented:
Create your "scripts" folder and place your scripts in that folder. In pages which much use the script files, include a line like this for each file that is needed:

<script type="text/javascript" src="scripts/functions.js"></script>

Open in new window


You may need to adjust the path based on the relativity of your page to the "scripts" folder. Be sure NOT to self-close the <script> tag--I don't know why, I just know it was a pain to figure out for me  = )
0
 
Bird757Author Commented:
Thank you. But something wierd has now happened to the default font?

What I did was add the 2nd line below:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="products.aspx.cs" Inherits="_Default" %>
<script type="text/javascript" src="scripts/functions.js"></script>

<!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>
... etc

Have I put it in the right place?
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
nishant joshiTechnology Development ConsultantCommented:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="products.aspx.cs" Inherits="_Default" %>

<!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>
<script type="text/javascript" src="scripts/functions.js"></script>
...
..

..
</head>
...


0
 
Bird757Author Commented:
Thank you!
0
 
käµfm³d 👽Commented:
NP. Glad to help  = )
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.