Assigning values to variables, Trouble changing the contents of a variable. |
Assigning values to variables, Trouble changing the contents of a variable. |
fhutt |
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? |
pandy |
Mar 27 2021, 09:59 PM
Post
#2
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,731 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'; |
fhutt |
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 |
fhutt |
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. |
pandy |
Mar 28 2021, 05:37 AM
Post
#5
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,731 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.
|
Lo-Fi Version | Time is now: 26th April 2024 - 08:52 AM |