The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> 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
Christian J
post Jan 14 2020, 05:36 PM
Post #2


.
********

Group: WDG Moderators
Posts: 9,628
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
crlx2
post Jan 14 2020, 06:22 PM
Post #3





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



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

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jan 14 2020, 06:30 PM
Post #4


.
********

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



You're welcome!
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

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: 19th March 2024 - 01:47 AM