Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can write var to file, but get 'undefined' displaying to html doc

Status
Not open for further replies.

easonc52

Technical User
Apr 21, 2001
14
US
Yes I'm new to this. X-) Thank you if you can see what I'm missing.

Want to save a one field form info to a file for later retrieval. Writing to the file is not a problem at this point, and the previous info is overwritten which is perfect for my purpose.

The action seems to take place whether or not the code is in a function, but I want to use the value to display in html (via alert, document write, etc.).

Currently getting 'undefined' with my document.write attempt (and I have looked at a lot of 'undefined' threads that I wasn't sure applied to my mistake).

<script language=&quot;JavaScript&quot;>
<!-- Hide Me
function test1(){
stuff = &quot;text I want to save to a file then call forth as a variable each time the page is opened. (just seeing if the text would react the same as a vaiable in text.Write as opposed to putting it there directly.&quot;
var TristateFalse = 0;
var ForWriting = 2;
myActiveXObject = new ActiveXObject(&quot;Scripting.FileSystemObject&quot;);
myActiveXObject.CreateTextFile(&quot;c:\\cisco\\project\\test.txt&quot;);
file = myActiveXObject.GetFile(&quot;c:\\cisco\\project\\test.txt&quot;);
test = file.OpenAsTextStream(ForWriting, TristateFalse);
test.Write(stuff);
test.Close();
}
// -->
</script>

<script language=&quot;JavaScript&quot;>
<!-- Hide Me
document.write(&quot;is this it?&quot; + test1()); //this is where the 'undefined' occurs (the 'test1()' part (I just got burnt out on this tonite and thought I'd ask))
// -->
</script>

Thanks again if you can assist.

Chuck :) &quot;Uh, honey, a P5 with a 20&quot; monitor is perfect for email&quot;
 
You have made a function call within the document.write to test1(). However, the test1 function does not return a value so why to you call the function within the document.write?? Mise Le Meas,

Mighty :)
 
If your function had the modification in red then it may work.

Code:
function test1(){
stuff = &quot;text I want to save to a file then call forth as a variable each time the page is opened. (just seeing if the text would react the same as a vaiable in text.Write as opposed to putting it there directly.&quot;
var TristateFalse = 0;
var ForWriting = 2;
myActiveXObject = new ActiveXObject(&quot;Scripting.FileSystemObject&quot;);
myActiveXObject.CreateTextFile(&quot;c:\\cisco\\project\\test.txt&quot;);
file = myActiveXObject.GetFile(&quot;c:\\cisco\\project\\test.txt&quot;);
test = file.OpenAsTextStream(ForWriting, TristateFalse);
test.Write(stuff);
test.Close();
}

return stuff;

Hope this helps. Klae

You're only as good as your last answer!
 
Thank you both for your replys. Obviously I have lots of studying to do and am not yet remebering all the stuff I've been studying in the last few weeks. X-) - onward and upward &quot;Uh, honey, a P5 with a 20&quot; monitor is perfect for email&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top