Click to See Complete Forum and Search --> : HELP... I need serious help quickly if possible
I need to have an html page generate a .txt file with information gathered from a form. My limitation is I need to do it in javascript (client side) since this will be a basic html page running on someone's pc, not the web.
Below is what I have at this point but it isn't working, can someone tell me why and how to fix it...
Thanks...
<HTML>
<HEAD>
<TITLE>Test</TITLE>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
function createText () { //Creates a .txt file
var TristateFalse = 0;
var ForWriting = 2;
myActiveXObject = new ActiveXObject("Scripting.FileSystemObject");
myActiveXObject.CreateTextFile("c:\\test.txt");
file = myActiveXObject.GetFile("c:\\test.txt");
text = file.OpenAsTextStream(ForWriting, TristateFalse);
text.Write('frmReference.byo_desc', 'frmReference.vendor');
text.Close();
}
// -->
</SCRIPT>
<form name="frmReference" method="post" action="">
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="134"> <p align="center">
<label>
<input name="byo_desc" type="radio" value="1">
Yes</label>
<label>
<input name="byo_desc" type="radio" value="0" checked>
No</label>
</td>
<td width="239">Do you fish</td>
<td width="148"> <div align="center">
<label>
<input name="vendor" type="radio" value="1">
Yes</label>
<label>
<input name="vendor" type="radio" value="0" checked>
No</label>
</div></td>
<td width="226">Do you ski</td>
</tr>
<tr>
<td height="10" colspan="4"><img src="images/grey_dot.gif" width="100%" height="1"></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" name="Submit" onClick="createText" value="Submit Form">
</div></td>
<td colspan="2"><div align="center">
<input name="Reset" type="reset" id="Reset" value="Reset Form">
</div></td>
</tr>
</table>
</form>
</BODY>
</HTML>
Khalid Ali
06-17-2003, 10:01 AM
There is a reasone for which JavaScript does not have the ability to read and write files on client system.If you must store some data,store it in cookies.
Thanks... I know JavaScript can do this b/c I can get it to work if I remove my form and just have the script write "Hello World" to a text file, but I need it to capture my form information.
Here is more background for you... I have a friend who just wants a page that he is going to have on his computer that he can check certain options and it will create a text file so he can some other app read it and run a report based on the data in the text file... Again, this is going to be local and not for the internet...
Thanks again.
djmc48
06-17-2003, 10:46 AM
sean,
heres how i did mine, and it worked fine...
var filename = "data.txt"; //initialize filename
var fso = new ActiveXObject("Scripting.FileSystemObject");
var file = fso.CreateTextFile(filename, true);
file.WriteLine('yep');
file.Close();
this creates it on my desktop, and overwrites it if its there.
hope this helps,
dj
djmc48
06-17-2003, 10:48 AM
ahh sorry, you posted yours while i was writing mine. ill look into it some more...
djmc48
06-17-2003, 10:59 AM
sean,
try this...
<HTML>
<HEAD>
<TITLE>Test</TITLE>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
function createText () { //Creates a .txt file
var filename = "test.txt"; //initialize filename
var fso = new ActiveXObject("Scripting.FileSystemObject");
var text = fso.CreateTextFile(filename, true);
if (document.frmReference.byo_desc[0].checked==true) { // yes checked
text.Write(document.frmReference.byo_desc[0].value+' ');
} else { // no checked
text.Write(document.frmReference.byo_desc[1].value+' ');
}
if (document.frmReference.vendor[0].checked==true) { // yes checked
text.Write(document.frmReference.vendor[0].value);
} else { // no checked
text.Write(document.frmReference.vendor[1].value);
}
text.Close();
}
// -->
</SCRIPT>
<form name="frmReference" method="post" action="">
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="134"> <p align="center">
<label>
<input name="byo_desc" type="radio" value="1">
Yes</label>
<label>
<input name="byo_desc" type="radio" value="0" checked>
No</label>
</td>
<td width="239">Do you fish</td>
<td width="148"> <div align="center">
<label>
<input name="vendor" type="radio" value="1">
Yes</label>
<label>
<input name="vendor" type="radio" value="0" checked>
No</label>
</div></td>
<td width="226">Do you ski</td>
</tr>
<tr>
<td height="10" colspan="4"><img src="images/grey_dot.gif" width="100%" height="1"></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" name="Submit" onClick="createText()" value="Submit Form">
</div></td>
<td colspan="2"><div align="center">
<input name="Reset" type="reset" id="Reset" value="Reset Form">
</div></td>
</tr>
</table>
</form>
</BODY>
</HTML>
dj
dj, thanks for your help... Can you tell me how to change where the file gets dropped?
Thanks so much...
Sean
djmc48
06-17-2003, 11:45 AM
sean,
umm thats something im not so sure about. I actually wrote script similar to this two days ago, but it just needed to go to the desktop. did you try writing the path how you did in your original posting? where exactly are you trying to put the file?
dj
I am trying to have the file dropped on a network drive... It will be in the same directory that the page resides in if that helps... So, the page will be in like m:\programs\test\somefolder\test.htm and the .txt file would need to be dropped in that folder as well.
Thanks again,
Sean
djmc48
06-17-2003, 12:10 PM
ok well i looked around, and everywhere seemed to use something similar to what you wrote down as a filename, in your case
var filename = "m:/programs/test/somefolder/test.txt";
should work as far as i know. i tried it using the c drive on my comp here and it worked. make sure you are using '/' not '\' in your path name that you are writing to.
dj
ok i got it to work to where it can drop the file on the m: drive, however it only works when I am running the htm page from my c: drive... If I move the actual htm file to the m: drive and run it from there there is a script error, but it goes so fast I can't see what it is... Any idea why it would run perfect locally, but when I move it out to the mapped drive m: and try to run it I get a script error.
thanks for all your help again.
djmc48
06-17-2003, 01:00 PM
hrmm...not quite sure. is the file open when you are trying to write to it? if it is it will give you an error, and thats the only one i ran into when i was doing this... if thats not the case, im not sure what it is. maybe someone else has done this before??? sorry i cant be of more help.
dj
Thanks... Below is the line that I am using to make the file, could it be something wrong with that?
var filename = "M:/MROI/HD2/PROGRAMS/Cooper/hddata/update_ind/test.txt";
Keep in mind my page resides in M:/MROI/HD2/PROGRAMS/Cooper/webpages
Thanks,
Sean
djmc48
06-17-2003, 01:56 PM
im not sure what the problem is, it could have something to do w/ the rest of your script. assuming that the directory path that you specify is correct (exists) i dont see anything wrong with it. i did tests on my computer w/ those exact paths (but on an E: drive instead of M) and it worked, so im not sure exactly what yours is doing. if you could catch what the error is somehow it would help.
dj
Could it have anything to do with the M: drive being a mapped drive? When I run it from my c: drive it works, but when I run it from the mapped/shared drive it doesn't.
Below is my actual code.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
a {
color: #000000;
text-decoration: none;
}
-->
</style>
</head>
<body link="#000000" vlink="#000000" alink="#000000">
<SCRIPT LANGUAGE="JavaScript">
<!--
function createText () { //Creates a .txt file
var filename = "M:/MROI/HD_2/PROGRAMS/Cooper/hddata/update_ind/test.txt"; //initialize filename
var fso = new ActiveXObject("Scripting.FileSystemObject");
var text = fso.CreateTextFile(filename, true);
if (document.frmReference.byo_desc[0].checked==true) { // yes checked
text.Write(document.frmReference.byo_desc[0].value+' ');
} else { // no checked
text.Write(document.frmReference.byo_desc[1].value+' ');
}
if (document.frmReference.fscl_wk[0].checked==true) { // yes checked
text.Write(document.frmReference.fscl_wk[0].value+' ');
} else { // no checked
text.Write(document.frmReference.fscl_wk[1].value+' ');
}
if (document.frmReference.merch_hierarchy[0].checked==true) { // yes checked
text.Write(document.frmReference.merch_hierarchy[0].value+' ');
} else { // no checked
text.Write(document.frmReference.merch_hierarchy[1].value+' ');
}
if (document.frmReference.store[0].checked==true) { // yes checked
text.Write(document.frmReference.store[0].value+' ');
} else { // no checked
text.Write(document.frmReference.store[1].value+' ');
}
if (document.frmReference.vendor[0].checked==true) { // yes checked
text.Write(document.frmReference.vendor[0].value+' ');
} else { // no checked
text.Write(document.frmReference.vendor[1].value+' ');
}
if (document.frmReference.vendor_sku_hierarchy[0].checked==true) { // yes checked
text.Write(document.frmReference.vendor_sku_hierarchy[0].value+' ');
} else { // no checked
text.Write(document.frmReference.vendor_sku_hierarchy[1].value+' ');
}
if (document.frmReference.wk_before[0].checked==true) { // yes checked
text.Write(document.frmReference.wk_before[0].value+' ');
} else { // no checked
text.Write(document.frmReference.wk_before[1].value+' ');
}
text.Close();
}
// -->
</SCRIPT>
<table width="759" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="759" height="37" bgcolor="#CCCC99"> <div align="center" class="Title">Reference
Panel </div></td>
</tr>
<tr>
<td height="37">
<form name="frmReference" method="post" action="process_req.htm">
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="4"> </td>
</tr>
<tr>
<td width="20%"> <p align="center">
<label>
<input name="byo_desc" type="radio" value="1">
Yes</label>
<label>
<input name="byo_desc" type="radio" value="0" checked>
No</label>
</td>
<td>BYO Description</td>
<td width="20%">
<div align="center">
<label>
<input name="vendor" type="radio" value="1">
Yes</label>
<label>
<input name="vendor" type="radio" value="0" checked>
No</label>
</div></td>
<td>Vendor Description</td>
</tr>
<tr>
<td width="20%"> <div align="center">
<label>
<input name="fscl_wk" type="radio" value="1">
Yes</label>
<label>
<input name="fscl_wk" type="radio" value="0" checked>
No</label>
</div></td>
<td>Fiscal Calendar</td>
<td width="20%">
<div align="center">
<label>
<input name="vendor_sku_hierarchy" type="radio" value="1">
Yes</label>
<label>
<input name="vendor_sku_hierarchy" type="radio" value="0" checked>
No</label>
</div></td>
<td>Vendor SKU Hierarchy</td>
</tr>
<tr>
<td width="20%"> <div align="center">
<label>
<input name="merch_hierarchy" type="radio" value="1">
Yes</label>
<label>
<input name="merch_hierarchy" type="radio" value="0" checked>
No</label>
</div></td>
<td>Merchandise Heirarchy</td>
<td width="20%">
<div align="center">
<label>
<input name="wk_before" type="radio" value="1">
Yes</label>
<label>
<input name="wk_before" type="radio" value="0" checked>
No</label>
</div></td>
<td>Prior week</td>
</tr>
<tr>
<td width="20%"> <div align="center">
<label>
<input name="store" type="radio" value="1">
Yes</label>
<label>
<input name="store" type="radio" value="0" checked>
No</label>
</div></td>
<td>Store Location</td>
<td width="20%">
<div align="center">
<label> </label>
</div></td>
<td> </td>
</tr>
<tr>
<td height="10" colspan="4"><img src="images/grey_dot.gif" width="100%" height="1"></td>
</tr>
<tr>
<td width="50%" colspan="2"><div align="center">
<input type="submit" name="Submit" onClick="createText()" value="Submit Form">
</div></td>
<td colspan="2"><div align="center">
<input name="Reset" type="reset" id="Reset" value="Reset Form">
</div></td>
</tr>
</table>
</form></td>
</tr>
</table>
</body>
</html>
djmc48
06-17-2003, 02:19 PM
sean,
sorry, but can you please explain the big picture? is process_req.htm what is 'running the report', or is a later page doing that? there is an easier way to do this if it is. you can send/recieve variables using javascript if you are just trying to get data from one html page to another. im not sure whats wrong with your file you posted, it worked fine on my comp. like i said im pretty new at working w/ activeX myself.
dj
process_req is just a basic page that has nothing on it but "Conratulations"
The reason for it is just to go to another page, it really does nothing.
I wonder why this isn't working on my computer... I have to think it has something to do with the drive mapping or something.
Any other thoughts
Sean
djmc48
06-17-2003, 02:38 PM
well one way to find out is to put them both on a drive that isnt mapped. if it works, then you know what the problem is. if not, possibly (temporarily) change your submit button from type='submit' to type='button'. that should keep you on the same page so that you can see what your error is before you get thrown to the 'congrats' page. just a thought.
dj
I changed the submit to type button and the error is below:
Automation server can't create object
djmc48
06-17-2003, 03:07 PM
not quite sure where to go with that. never even heard of an automation server b4. hopefully someone else can help you. :confused:
dj