JavaScript Forum JS Made Easy: Free JavaScripts Tutorials Example Code
About This Product
FontsMadeEasy.com
 
The Business Internet
Find it on This page:
 
| Over 5000 Free Fonts | Tutorials | Javascript Forum | Other Javascript Resources | Cheat Sheet

     
Jsmadeeasy Forums Home   Search   Login   Register   Member List  
JS Made Easy  > JavaScript programming  > How can I use a variable in the src-attribute of the <script>-tag?  
 
Display using:  
Previous Thread :: Next Thread 
 Author Thread: How can I use a variable in the src-attribute of the <script>-tag?
solander is not online. Last active: 8/17/2004 3:49:33 AM solander
Top 25 Poster
Joined: 17 Aug 2004
Total Posts: 4
 
How can I use a variable in the src-attribute of the <script>-tag?
Posted: 17 Aug 2004 02:03 AM
I have a javascript variable that contains the name of the file I would like to use i a <script>-tag

mySourcefile = "dynSrc.js"
<script langage="Javascript" src="xxx">
</script>

How do I write the src-attribute to reference the variable mySourcefile ?

Thanks,
Michael Solander
solander is not online. Last active: 8/17/2004 3:49:33 AM solander
Top 25 Poster
Joined: 17 Aug 2004
Total Posts: 4
 
Re: How can I use a variable in the src-attribute of the <script>-tag?
Posted: 17 Aug 2004 03:49 AM
I recieved an answer at webdeveloper.com. For you who might need it, this is the way:

<script id="wibble" type="text/javascript"></script>
document.getElementById('wibble').src = 'yourFile.js';

Kind regards,
Michael Solander
Admin is not online. Last active: 12/1/2005 12:27:12 PM Admin
Top 25 Poster
Forum Moderator
Joined: 28 Jul 2004
Total Posts: 15
 
Re: How can I use a variable in the src-attribute of the <script>-tag?
Posted: 17 Aug 2004 09:49 AM
You also can use this code:

<script type="text/javascript">
var js_file = "file.js";
document.writeln('<script type="text/javascript" src="' + js_file + '"');
</script>
Previous Thread :: Next Thread 
Page 1 of 1
 
Jsmadeeasy.com  > JS Made Easy  > JavaScript programming  > How can I use a variable in the src-attribute of the <script>-tag?