PDA

View Full Version : edit file in textarea



slimt_slimt
11-27-2006, 03:03 PM
Hi there,

This is a small script, that loads a file, which you can edit and later save. The only problem is, that is saves also the content of <option> field.

so each time i got the "choose 1.txt 2.txt" saved in txt file, which i don't want. where seems to be a mistake?

thank you very much!

the code:
<html xmlns:msie>
<msie:download id="downloader"
style="behavior:url(#default#download)" />
<HEAD>
<SCRIPT>
function fetchURL(url) {
if ((location.host == '' && url.indexOf(location.protocol) == -1)
||
url.indexOf(location.host) == -1)
{
netscape.security.PrivilegeManager.enablePrivilege
("UniversalConnect");
}
var dest = new java.net.URL(url);
var dis = new java.io.DataInputStream(dest.openStream());
var res = "";
while ((line = dis.readLine()) != null) {
res += line;
res += java.lang.System.getProperty("line.separator");
}
dis.close();
return res;
}
</SCRIPT>
<SCRIPT>
function loadFile (fileName) {
if (document.layers) {
var i = new Image();
i.src = fileName;
var fileURL = i.src;
document.formName.file.value = fetchURL(fileURL);
}
else if (document.all && document.getElementById)
downloader.startDownload(fileName, displayFile);
}
function displayFile (text) {
document.formName.file.value = text;
}
function saveFile (fname)
{
document.execCommand('SaveAs',null,fname)
}
function saveText(val)
{
document.execCommand('SaveAs', null, val);
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="formName">
<SELECT NAME="files"
ONCHANGE="if (this.selectedIndex > 0)
loadFile(this.options[this.selectedIndex].value);">
<OPTION selected="selected">Choose:</OPTION>
<OPTION VALUE="1.txt">1.txt</OPTION>
<OPTION VALUE="2.txt">2.txt</OPTION>
</SELECT>

<TEXTAREA NAME="file" ROWS="20" COLS="40" WRAP="off"></TEXTAREA>
<input type="button" value="Save1" onClick="saveFile('1.txt');">
<input type="button" value="Save2" onClick="saveFile('2.txt');">
</FORM>
</BODY>
</HTML>