Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Include File Help

Status
Not open for further replies.

usp004

ISP
Jul 10, 2000
46
US
I am using an include file in my ASP page which contains JavaScript code to validate a date input field. If I leave the JavaScript code in-line on the ASP page everything works fine... but when I move the JavaScript code to another file and reference it via and INCLUDE file.... it doesnt work... basically it cannot find the function. Here is a simpified code example of what I am doing:

ASP PAGE:

<HTML><HEAD>
<!--#include file=&quot;DateValidation.js&quot;-->
<BODY bgColor=#ffffff>
.
.
.
<INPUT name=Submit onclick=&quot;PrintHello();&quot;>
.
.

----------------------------------------------------------
INCLUDE FILE: (DateValidation.js)

<script language=&quot;JavaScript&quot;>
<!--
Function PrintHello(){
alert(&quot;HELLO&quot;)
}
//-->
</script>


Thanks in advance.
[sig][/sig]
 
Try this example...

default.asp
Code:
<html>
<head>
<!--#include file=&quot;DateValidation.js&quot;-->
</head>
<body>
<input type=button value=&quot;Hello&quot; onclick=&quot;PrintHello();&quot;>
</body>
</html>

DateValidation.js
Code:
<script language=&quot;JavaScript&quot;>
<!--
function PrintHello(){
    alert(&quot;HELLO&quot;);
}
//-->
</script>

A) Unless it was simply misprint then your function was spelled Function (use lowercase)
B) If the .js file is in a different folder if you want to use include file then you must specify the file path relative to the .asp file. As is above both files must be in the same folder. If you use include virtual then you must specify the file path relative to the site.

Hope this helps,
Rob [sig][/sig]
 
Alternately, you can use this syntax:
<script language='javascript' src='DateValidation.js'>

This has the advantage that it is cached, even if the page containing the line has a meta tag to disable caching. So it will only be downloaded once, not with each page as happens with the #include.

Note that if you use this syntax, you must remove all <script> and <!-- tags from inside the file.
[sig]<p>nick bulka<br><a href=mailto: > </a><br><a href= </a><br>Get your technical books at Bulka's Books<br>
[/sig]
 
Good call Nick. I forgot to mention that.
[sig]<p>Rob<br><a href=mailto:robschultz@yahoo.com>robschultz@yahoo.com</a><br>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
"Focus on the solution to the problem,<br>
not the obstacles in the way."<br>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top