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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

include javascript file in asp

Status
Not open for further replies.

angeliamy

Programmer
Aug 28, 2003
16
US
I have several asp files that use the same javascript information. Instead of repeating the javascript on each asp page I'm wanting to use an include statement within the asp and refer to a singel javascript file. When I do this it disables the submit button on the original asp page. I really don't know why. Everything else on the page works. I'm referring to the include file as .asp but it has nothing but javascript in it. Can this not be done or is there a better way to do it?
 
There may be a better way to do it. In the same virtual folder where your ASP files reside, create a .js file and include your javascript code in that file. Then, in the ASP files, include a line similar to this:
Code:
<script language="javascript" src="jsfunc.js">
//The jsfunc.js file holds all of the javascript code.</script>


------------------------------------------------------------------------------------------------------------------------
If you don't have a sense of humor, you probably don't have any sense at all.
- Anonymous
 
I tried that and that didn't work either. I'm not sure why though. The javascript file has 3 different javascripts in it but that shouldn't matter. The asp file has none and there isn't anything apparent conflicting. A little more detail- the form is a typical form in asp, the include javascript file is a double dropdown populating 3 text boxes automatically. When I do include the javascript on the original asp file it still disables the submit button. So no matter what the asp file doesn't like the javascript, but they do work independently. Suggestions?
 
sounds like you've taken bits of JS from all over a page ( the original ) and put them into a single file ( the include ) as a group, if they were seperate before, they would have "fired" at different points thru the flow of the asp page, and in turn, dumping them all into a group at the top or bottom of a page might be causing the issue. the main thing is look at the logical flow of the page, does a function need to fire later or earlier than it is, etc.

also, try using a SSI (<!--#include file="whatever"-->) , becuase it will just inject the code right in as if it was part of the page. if that doesn't work out on the first try, take the original file, take all the code IN page that you put into the include file and move it all together as if it was the include, and run the page with it's original code in the page, just moved to whereever your include line would be.

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
 
Be careful that your "jsfunc.js" page that you include with that javascript include, does not contain any <script> tags - that makes the entire included script blowup.

If it does contain <script> tags, use DreX's server-side include <!--#include file="whatever"--> or
<!--#include virtual="/includes/jsfunc.xxx"--> to get the job done.
Bent
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top