JavaScript

Moderators: None (Apply to moderate this forum)
Number of threads: 2058
Number of posts: 5158

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
How can I use a variable to call a .js file Posted by jaycss on 22 Oct 2001 at 10:28 AM
I need some help, here.
I need to call this .js file automatically,
not with an onClick function.
How can I call a .js file in a situation like the following:
----------------------------------
<SCRIPT LANGUAGE="JavaScript">
var cnt = "2";
</SCRIPT>
<script language="JavaScript" src=cnt+"1.js"></script>
----------------------------------
This call should load a .js file named "21.js".
I have tried all kinds of stuff. Now my mind is mush.
Please help, if you can.

Report
Come on! Somebody has to know how. Posted by jaycss on 23 Oct 2001 at 11:02 PM
: I need some help, here.
: I need to call this .js file automatically,
: not with an onClick function.
: How can I call a .js file in a situation like the following:
: ----------------------------------
: <SCRIPT LANGUAGE="JavaScript">
: var cnt = "2";
: </SCRIPT>
: <script language="JavaScript" src=cnt+"1.js"></script>
: ----------------------------------
: This call should load a .js file named "21.js".
: I have tried all kinds of stuff. Now my mind is mush.
: Please help, if you can.
:


Report
Re: Come on! Somebody has to know how. Posted by xapis on 24 Oct 2001 at 1:16 PM
: : I need some help, here.
: : I need to call this .js file automatically,
: : not with an onClick function.
: : How can I call a .js file in a situation like the following:
: : ----------------------------------
: : <SCRIPT LANGUAGE="JavaScript">
: : var cnt = "2";
: : </SCRIPT>
: : <script language="JavaScript" src=cnt+"1.js"></script>
: : ----------------------------------
: : This call should load a .js file named "21.js".
: : I have tried all kinds of stuff. Now my mind is mush.
: : Please help, if you can.
: :
:
:

I believe all you should have to do is the following:

<head>
<!--#include file="21.js" -->
</head>

And 21.js includes:

<script language="JavaScript">
alert("Hello there!");
</script>

Remember 21.js must be in the same directory as your calling file. Otherwise use the following:

<!--#include virtual="http://www.ursite.com/functions/21.js" -->




Report
Re: Sorry, won't meet requirements Posted by jaycss on 24 Oct 2001 at 2:37 PM
: : : I need some help, here.
: : : I need to call this .js file automatically,
: : : not with an onClick function.
: : : How can I call a .js file in a situation like the following:
: : : ----------------------------------
: : : <SCRIPT LANGUAGE="JavaScript">
: : : var cnt = "2";
: : : </SCRIPT>
: : : <script language="JavaScript" src=cnt+"1.js"></script>
: : : ----------------------------------
: : : This call should load a .js file named "21.js".
: : : I have tried all kinds of stuff. Now my mind is mush.
: : : Please help, if you can.
: : :
: :
: :
:
: I believe all you should have to do is the following:
:
: <head>
: <!--#include file="21.js" -->
: </head>
:
: And 21.js includes:
:
: <script language="JavaScript">
: alert("Hello there!");
: </script>
:
: Remember 21.js must be in the same directory as your calling file. Otherwise use the following:
:
: <!--#include virtual="http://www.ursite.com/functions/21.js" -->
:
:
:
:
Thanks for the effort. This has all got to be dynamic. By that I mean, not HARD CODED.

Report
I found the solution on another web site. Posted by jaycss on 24 Oct 2001 at 2:39 PM
: I need some help, here.
: I need to call this .js file automatically,
: not with an onClick function.
: How can I call a .js file in a situation like the following:
: ----------------------------------
: <SCRIPT LANGUAGE="JavaScript">
: var cnt = "2";
: </SCRIPT>
: <script language="JavaScript" src=cnt+"1.js"></script>
: ----------------------------------
: This call should load a .js file named "21.js".
: I have tried all kinds of stuff. Now my mind is mush.
: Please help, if you can.
:
I will post the answer later tonight for anyone that might want to know how to do this. It ended up being pretty easy.

Report
This how to do it. Posted by jaycss on 24 Oct 2001 at 10:25 PM
: I need some help, here.
: I need to call this .js file automatically,
: not with an onClick function.
: How can I call a .js file in a situation like the following:
: ----------------------------------
: <SCRIPT LANGUAGE="JavaScript">
: var cnt = "2";
: </SCRIPT>
: <script language="JavaScript" src=cnt+"1.js"></script>
: ----------------------------------
: This call should load a .js file named "21.js".
: I have tried all kinds of stuff. Now my mind is mush.
: Please help, if you can.
:
This how to do it. I even got it to loop thru a 'for' loop and load 4 different .js files. It will read the following files:
('11.js' & '21.js' & '31.js' & '41.js')
-------------
<html>
<head>
<title></title>
</head>
<body>
<script language="JavaScript">
<!--
var cnt = 4;
for (file=1;file<cnt;file++)
document.write('<script src="' + file + '1.js"><\/script>');
//-->
</script>
</body>
</html>




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.