The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Assigning values to variables, Trouble changing the contents of a variable.
fhutt
post Mar 27 2021, 09:18 PM
Post #1





Group: Members
Posts: 6
Joined: 25-March 21
Member No.: 27,870



I have a snippet of code I am having trouble with.
This code works:
CODE

<script>
    var loc=iName;
    alert('File to reach -- ' + loc + ' --');
</script>


This code does not work:
CODE

<script>
    var loc=folder1/folder2/iName;
    alert('File to reach -- ' + loc + ' --');
</script>


I am unable to add to the contents of iName. My syntax must be wrong.
How could I fix this?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Mar 27 2021, 09:59 PM
Post #2


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,730
Joined: 9-August 06
Member No.: 6



Neither of them works. You must quote the values of the variables.

CODE
var loc = 'iName';

CODE
var loc = 'folder1/folder2/iName';
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
fhutt
post Mar 27 2021, 10:24 PM
Post #3





Group: Members
Posts: 6
Joined: 25-March 21
Member No.: 27,870



Yes, a step closer.
Unfortunately, iName has contents originally of info.txt.

Now the result of
var loc = 'folder1/folder2/iName';
shows: folder1/folder2/iName

instead of: folder1/folder2/info.txt

This post has been edited by fhutt: Mar 27 2021, 10:25 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
fhutt
post Mar 27 2021, 10:46 PM
Post #4





Group: Members
Posts: 6
Joined: 25-March 21
Member No.: 27,870



Found the solution.

CODE

var loc = 'folder1/folder2/'+iName;


Thank you for direction.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Mar 28 2021, 05:37 AM
Post #5


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,730
Joined: 9-August 06
Member No.: 6



Yes. I first though iName was a variable too. But then when I saw the second example I thought it wasn't. biggrin.gif
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 April 2024 - 06:07 PM