Using javascript, how to open a text-file or html-file from a web-page and load the contents in the text file or the html code to a textarea. Please Dont tell me this not possible using javsscript, it is possible but i dont know the code and my bro not coming home for a week . Example codes will be greatly appreciated. (i have already asked this question but everyone seemed to concentrate on the other part of the question.)
<html>
<body>
<form name="abc">
<textarea name="text">loaded text here</textarea>
<input type="button" onClick=""> open file
</form>
</body>
</html>
I found this in a forum , dont remember name , This is a working code but can only load text files .... now the question is how can I get it to fetch htmlcodes from a html file.
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
var ForReading = 1, ForWriting = 2, ForAppending = 8;
var objFSO = new ActiveXObject("Scripting.FileSystemObject");
function loadFile(btn, obj, div, fld) {
objFile = objFSO.GetFile(obj.value);
objStream = objFile.OpenAsTextStream(ForReading);
fld.value = objStream.ReadAll();
objStream.Close();
objStream= null;
fileSpecs(div, btn);
objFile = null;
return true;
}
</script>
</head>
<body>
<form name="myForm" onsubmit="return false;">
<textarea rows="25" name="fileArea" cols="70"
onkeypress="return checkText(this, btnSave);"></textarea> </td>
<input type="file" name="fileName" size="50"
onchange="return checkFile(this, document.getElementById('fileSpec'), btnLoad, btnSave, fileArea);">
<input type="button" name="btnLoad" value="Load"
onclick="return loadFile(this, fileName, document.getElementById('fileSpec'), fileArea);">
</form>
</body>
</html>
This is another one the coder claims it to be working but it is nt working for me , please execute this code if u hav time ...if it is working please provide the complete code here. (coded by Ancora)
<html>
<head>
<script type="text/javascript">
function init(){
var extText = window.frames.messageTxt.document.body.lastChild.lastChild.data;
extText = extText.replace(/[\r\n]/g," ");
document.forms[0].nMessage.value = extText;
}
window.onload=init;
</script>
</head>
<body>
<iframe name='messageTxt' src='txtData.txt' style='display:none'></iframe>
<form>
<textarea name='nMessage'></textarea>
<input type="button" value="click" onClick="init()">
</form>
</body>
</html>
i guess no can do this...i had a javascript that can load htmlcode form an external html file into the textarea. But i lost that file, sad no one here has the scripting abilities to create a js function (or active x) that can do the same.