The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> still problem with script and variable
crlx2
post Jan 14 2020, 04:58 PM
Post #1





Group: Members
Posts: 6
Joined: 14-January 20
Member No.: 27,121



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



User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
 
Reply to this topicStart new topic
Replies
Christian J
post Jan 14 2020, 05:36 PM
Post #2


.
********

Group: WDG Moderators
Posts: 9,665
Joined: 10-August 06
Member No.: 7



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).



User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Posts in this topic
crlx2   still problem with script and variable   Jan 14 2020, 04:58 PM
Christian J   but this doesn't work: var FileName=".....   Jan 14 2020, 05:36 PM
crlx2   god bless you ! it works, it's just what i...   Jan 14 2020, 06:22 PM
Christian J   You're welcome!   Jan 14 2020, 06:30 PM


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 10th May 2024 - 04:44 AM