From: Terence on 11 Nov 2009 17:42 I actually use Fortran for programming, and wish to call from Fortran, any process which will permit me to call a browser, while passing an HTM form as a file name, in order to capture the entered data. The calling opeartion is clear and works. OPera and Internat Explores, as samples, do the job, but the storage so far achieved is only the ascii contents of the fields and not filed-based coded replies and texts. I then want to repeat the process with another input, the same form and another stored output. Of course, I know how to do the above reqirement with a web-based or local-based form and using the POST mechanism to get one e-mailed message per form entry to a (any specified) mailbox via a "Submit"- type completion button. Now, there are very many programs involved with the form generation and the processing of the captured data, which currently relies on the Modzilla form-generated and coded ascii e-mailed messages with the attached data file. So changing one program or providing anothe is possible, but is would not be possible to change all programs (>100). I wish to do something similar to the working "POST and receive" process, but wish to store the produced file (in the Modzilla coding) on a local drive (the same cpu or local office net drives). The following code processes the simple test form and writes the named file, but only with the ascii contents of the text fields used. I need radio, multiple, value and text fields and I need the filed-name prefixes to each reply as per Modzilla coding. How can I do this? Can anyone offere a modified version of what is a basic satrt (below)? <html> <head> <script language="javascript"> function Writedata() { var fso = new ActiveXObject("Scripting.FileSystemObject"); var write_id; write_id = document.getElementById('write_id').value ; var s = fso.CreateTextFile(write_id, true); s.WriteLine(document.getElementById('name_id').value); s.WriteLine(document.getElementById('id_id').value); s.Close(); } </script> </head> <body> name : <input type="text" name="name" value="" id="name_id"><br/> Address : <input type="text" name="id" value="" id="id_id"><br/> Write file to : <input type="text" name="write" value="C://formdata// filename.att" id="write_id"><br/> <input type="button" onclick="Writedata(this.form)" value="STORE"> </body> </html>
From: Terence on 11 Nov 2009 17:46 Sorry about the typos which seemed OK here (well, most) but not in the post!
From: Terence on 13 Nov 2009 21:17 On Nov 12, 9:46 am, Terence <tbwri...(a)cantv.net> wrote: > Sorry about the typos which seemed OK here (well, most) but not in the > post! I was rather hoping somebody can contribute to this question. The browser must have the form data content in memory, plus the labels and probably even a buffer with the proposed POST action text block. All I wan to do is store this buffer (in Modzilla coded format) on a local disk drive.
From: Stefan Weiss on 14 Nov 2009 02:24 On 14/11/09 03:17, Terence wrote: > On Nov 12, 9:46 am, Terence <tbwri...(a)cantv.net> wrote: >> Sorry about the typos which seemed OK here (well, most) but not in the >> post! > > I was rather hoping somebody can contribute to this question. I can only speak for myself, of course, but I found your problem description kind of hard to read. That could explain the absence of helpful replies. I'm still not sure if I understand the question correctly, but it looks like you want to save a text file locally with JavaScript from a Mozilla browser (Firefox?). That's possible, but not with the ActiveX/FSO approach. I've added an example which should save the file for you in Firefox and IE, assuming that access is granted. You'll need to add error handling, form validation, and proper form serialization if your form has radio buttons, select fields, etc. Note that the file path is now "C:/formdata/filename.att" instead of "C:/formdata/filename.att". cheers, stefan <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>File save test</title> </head> <body> name : <input type="text" name="name" value="" id="name_id"><br> Address : <input type="text" name="id" value="" id="id_id"><br> Write file to : <input type="text" name="write" value="C:/formdata/filename.att" id="write_id"><br> <input type="button" onclick="saveFile()" value="STORE"> <script type="text/javascript"> function getVal (id) { return document.getElementById(id).value; } function getFilePath () { // (snip validation) return getVal("write_id"); } function getFileData () { // (snip validation) var data = []; data.push(getVal("name_id")); data.push(getVal("id_id")); return data.join("\r\n"); } function saveFile () { var path = getFilePath(), data = getFileData(); if (typeof this.netscape == "object" && typeof netscape.security == "object") { saveFile_Moz(path, data); } else if (typeof this.ActiveXObject != "undefined") { saveFile_ActiveX(path, data); } } function saveFile_ActiveX (path, data) { var fso = new ActiveXObject("Scripting.FileSystemObject"), file = fso.CreateTextFile(path, true); file.Write(data); file.Close(); } function saveFile_Moz (path, data) { try { netscape.security.PrivilegeManager .enablePrivilege("UniversalXPConnect"); } catch (e) { alert("Local file system access denied; aborting."); return; } var cc = Components.classes, ci = Components.interfaces, file = cc["@mozilla.org/file/local;1"] .createInstance(ci.nsILocalFile), perms = parseInt("644", 8), outStream; file.initWithPath(path); if (!file.exists()) { file.create(ci.nsIFile.NORMAL_FILE_TYPE, perms); } outStream = cc["@mozilla.org/network/file-output-stream;1"] .createInstance(ci.nsIFileOutputStream); // ioFlags -1 indicates default mode: // PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE // see http://mxr.mozilla.org/mozilla-central/source/ (join) // (join) netwerk/base/public/nsIFileStreams.idl#86 outStream.init(file, -1, perms, 0); outStream.write(data, data.length); outStream.close(); } </script> </body> </html>
From: Stefan Weiss on 14 Nov 2009 02:27 On 14/11/09 08:24, Stefan Weiss wrote: > Note that the file path is now "C:/formdata/filename.att" instead of "C://formdata//filename.att".
|
Next
|
Last
Pages: 1 2 3 4 5 6 Prev: IE/FF XHR multi-file upload Next: html form in javascript variable |