I've got some strange behaviour with a javascript file, when I have multiple functions in the .js file.
I have a Logging.js file, which writes to a text file:
function WriteLog(message)
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var textFile = fso.OpenTextFile("C:\\Users\\sysadmin\\Desktop\\Tom's Work Area\\file.txt", 8, true);
textFile.WriteLine(message);
textFile.Close();
}
And I call this function in my HTML like so:
<head>
<script src="C:\\Users\\sysadmin\\Desktop\\Tom's Work Area\\Logging.js" type="text/Javascript" </script>
</head>
<body>
<script>
WriteLog("text");
</script>
</body>
Which works perfectly, however, when I add another function to my Logging.js file:
function getDate()
{
try{
var date = new Date();
var year = date.getFullYear();
var day = date.getDate();
if (day < 10)
{
day = "0" + day;
}
var month = date.getMonth() + 1;
if (month < 10)
{
month = "0" + month;
}
var hour = date.getHours();
var minutes = date.getMinutes();
if (minutes <= 9)
{
minutes = "0" + minutes;
}
var seconds = date.getSeconds();
if (seconds <= 9)
{
seconds = "0" + seconds;
}
var dateString = "" + day "/" + month + "/year" + " " + hours + ":" + minutes ":" + seconds;
return dateString;
}
catch(e)
{
Script.writeln(e.description);
}
}
Then the writing to a text file doesn't even work, as if the Logging.js file doesn't work anymore! Even when I don't call the getDate() function.
Any thoughts? Thanks!
Typo:
var dateString = "" + day "/" + m
var dateString = "" + day + "/" + m
Missing + on the string concat. minutes is missing a + sign as well.