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!

How do I make the SRC part of the SCRIPT tag dynamic? 1

Status
Not open for further replies.

Hangaard

Programmer
Apr 12, 2000
5
DK
How do I insert a variable SRC in the script tag?<br>I want to insert a file containing an array-variable into my javascript.<br>Sometimes the file is placed in my &quot;A&quot;-directory, sometimes in my &quot;B&quot;-directory and so on.<br>If it is not possible to insert the variable in the script tag, can I then in any way move the SRC part down into the javascript-code?
 
you could use two seperate scripts, one to decide which directory. this one would also use the document.write() method to write in the second code.<br><br>here is a small sample, but for a working script, I think we need more information.<br><br>&lt;script language=&quot;javascript&quot;&gt;<br>function makeScripts(){<br>var ScriptSrcStr;<br>if (<i>condition for directory A</i>){<br>ScriptSrcStr=' else {<br>ScriptSrcStr=' language=\&quot;javascript\&quot; src=\&quot;'+ScriptSrcStr+'\&quot;&gt;');}<br>&lt;/script&gt;<br><br>&lt;body onload=makeScripts()&gt;<br>------------------------end of script-----------------------<br><br>if you could provide information on the conditions for the directory choice, I could write a complete script<br><br> <p>theEclipse<br><a href=mailto:eclipse_web@hotmail.com>eclipse_web@hotmail.com</a><br><a href=robacarp.webjump.com>robacarp.webjump.com</a><br>**-Trying to build a documentation of a Javascript DOM, crossbrowser, of course. E-mail me if you know of any little known events and/or methods, etc.
 
Thanks for helping me theEclipse,<br><br>I have tried using your example, but It didn't work. Here's the code (variable names translated from Danish [the language - not the pastry :) ])<br><br><FONT FACE=monospace>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br> &lt;title&gt;Photo series&lt;/title&gt;<br><font color=red>&lt;!-- photoalbum.dat contains an array &quot;photos&quot;, holding the paths of different series of photos--&gt;</font><br>&lt;script language=&quot;JavaScript&quot; src=&quot;photoalbum.dat&quot;&gt;&lt;/script&gt;<br>&lt;script language=&quot;JavaScript&quot;&gt;<br> photosPath = photos[0]; <font color=red>// just to simplify the example I choose the first series of photos</font><br> function makePhotoList()<br> {<br> <font color=red>// I want to include the array (photos.dat) from a dynamic directory name</font><br> document.writeln('&lt;script language=\&quot;javascript\&quot; src=\&quot;'+photosPath+'photos.dat\&quot;&gt;');<br> }<br>&lt;/script&gt;<br>&lt;/head&gt;<br>&lt;body onload=&quot;makePhotoList();&quot;&gt;<br>&lt;script language=&quot;JavaScript&quot; src=&quot;js/photos.js&quot;&gt;&lt;/script&gt;<font color=red>&lt;!-- photos.js contains the functions that build the HTML --&gt;</font><br>&lt;script language=&quot;JavaScript&quot;&gt;<br>writePage(); <font color=red>// writes the HTML (a dynamic table setup with thumbnails to the left and the selected photo to the right)</font><br>&lt;/script&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</font><br><br>I hope the problem is described well enough for others than myself to understand it.
 
what errors does it give?<br>what is contained in photos[0]?<br>where is the assignment for photos[0]?<br><br>just a couple questions I have for help with debugging.<br><br> <p>theEclipse<br><a href=mailto:eclipse_web@hotmail.com>eclipse_web@hotmail.com</a><br><a href=robacarp.webjump.com>robacarp.webjump.com</a><br>**-Trying to build a documentation of a Javascript DOM, crossbrowser, of course. E-mail me if you know of any little known events and/or methods, etc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top