Help - Search - Members - Calendar
Full Version: Assigning values to variables
HTMLHelp Forums > Programming > Client-side Scripting
fhutt
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
Neither of them works. You must quote the values of the variables.

CODE
var loc = 'iName';

CODE
var loc = 'folder1/folder2/iName';
fhutt
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
fhutt
Found the solution.

CODE

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


Thank you for direction.
pandy
Yes. I first though iName was a variable too. But then when I saw the second example I thought it wasn't. biggrin.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2024 Invision Power Services, Inc.