Printable Version of Topic

Click here to view this topic in its original format

HTMLHelp Forums _ Client-side Scripting _ still problem with script and variable

Posted by: crlx2 Jan 14 2020, 04:58 PM

Sorry for my indecision to express my problem:

this works:
<script src="../clients/code.js"></script>


but this doesn't work:

var FileName="../clients/code.js";
<script src="+FileName+"></script>

I'm not expert to understand the error, but i need to use a variable
thank you




Posted by: Christian J Jan 14 2020, 05:36 PM

QUOTE(crlx2 @ Jan 14 2020, 10:58 PM) *

but this doesn't work:

var FileName="../clients/code.js";
<script src="+FileName+"></script>

You can't use javascript code outside a SCRIPT element like that.

QUOTE
I'm not expert to understand the error, but i need to use a variable

What is the variable's value? The URL of the javascript file, or the file's contents, or the file itself? If it's just the URL, you might do something like:

CODE
<script type="text/javascript" id="foo"></script>

<script type="text/javascript">
var url="../clients/code.js";
document.getElementById('foo').src=url;
</script>

(note that you can't both use an URL and embedded javascript code in the same SCRIPT element, hence the need for two SCRIPT elements).




Posted by: crlx2 Jan 14 2020, 06:22 PM

god bless you ! it works, it's just what i was looking for!
thanks a lot Christian


Posted by: Christian J Jan 14 2020, 06:30 PM

You're welcome!

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)