0

I have been trying to create my own type of blog style website where you post to a .txt file using javascript.

I have been encountering lots of trouble with this and have only managed to find a tiny part of what I want. Can you please help me!!!

Code:

<html><head>
<script language="javascript">
function Writedata()
  {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var write_id;
write_id = document.getElementById('write_id').value ;
alert('The data has been written to \n' + write_id);
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>
Date : <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="" id="write_id"><br/>
<input type="button" onclick="Writedata()" value="submit">
</body>
</html>

To reiterate the question, Please can you make the Date section add a date on webpage load and have the text from the address append to a file from the 'write file to' input.

Thanks!

Bradley Beeke
  • 13
  • 1
  • 5
  • What made you think you can write to the fileStorage from the browser? – Ronni Skansing Jan 29 '15 at 10:14
  • Related to : http://stackoverflow.com/questions/12928117/how-to-use-filesystemobject-to-read-file-in-javascript . You cannot access the file system from your browser. – NeoPix Jan 29 '15 at 10:14
  • I have seen one work actually but it was not what I was looking for and I could not adapt it due to my little knowlage in javascript. – Bradley Beeke Jan 29 '15 at 10:16
  • When did you see this .. 10 years ago? this makes little or no sense today. – Ronni Skansing Jan 29 '15 at 10:16
  • But it writes to the text file but does not append it. – Bradley Beeke Jan 29 '15 at 10:17
  • And I have found the working one yesterday actually – Bradley Beeke Jan 29 '15 at 10:19
  • Then how would I do this to create what I want then? – Bradley Beeke Jan 29 '15 at 10:20
  • You save the data serverside and make a AJAX request clientside. Or use any of the clientside storages such as cookies or localStorage. But do not proceed with this ActiveXObject, it pure crazyness and will not work in any browsers (except old IE) – Ronni Skansing Jan 29 '15 at 10:20
  • so the only way to do this is to use local storage or cookies because I want to make it simple. – Bradley Beeke Jan 29 '15 at 10:23
  • Well local storage and cookies are super simple so I bet that is exactly what you are looking for ;) – Ronni Skansing Jan 29 '15 at 10:24
  • Okay great but what would happen if i use them? will it post to the actual inner html of the page or what? – Bradley Beeke Jan 29 '15 at 10:25
  • They both allow you to persist data on the client (browser) and retrieve it at a later point (even after browser has been closed). What you do with the data, like put it inside some html or use it for calculation in the background or even send it to a remote server via sockets, is up to you. You should be able to find endless information and code samples on this subject – Ronni Skansing Jan 29 '15 at 10:27
  • Okay but how would I do it? do you have a example of something I can test? because my knowlage of Local storage is even worse than that of javascript – Bradley Beeke Jan 29 '15 at 10:30
  • If I use Local Storage will it display for other users?? because the whole point of it was to be a blog essentialy – Bradley Beeke Jan 29 '15 at 10:32
  • You should be able to find the material you need. If you want to make a blog you will have to save the content serverside, then it will not work with cookies, localStorage or even file storage as you tried first. You need hosting. – Ronni Skansing Jan 29 '15 at 10:48

0 Answers0