...

View Full Version : HELP: Copy and Save to a notepad onclick



mikoto
05-27-2012, 03:55 PM
what i was hoping to happen is when i click on the CREATE button i will be able to copy the values of cxname and mynotes and that the same time, when i click on CREATE button, it will create a .txt file in my desktop and will store there the values of cxname and dissue and it will just add the other values, not overwrite the existing contents in the .txt file everytime i click the CREATE button.



<script LANGUAGE="JavaScript">

<!-- Begin
var messages = new Array(6);
messages[0] = "";
messages[1] = "You selected option 1";
messages[2] = "You selected option 2";
messages[3] = "You selected option 3";
messages[4] = "You selected option 4";
messages[5] = "You selected option 5";
function messageReveal() {
var messageindex = document.formb.dissue.selectedIndex
document.formb.mynotes.value = messages[messageindex];
}
// End -->
</script>

<body>

<center>
<form name="formb">

<tr>
<td class="label2"><b>Name </b></td>
<TD><input class="textbox" name="cxname"></td>
</tr>

<p><select name="dissue" OnChange="messageReveal()">
<option value="0">Select</option>
<option>First Option</option>
<option>Second Option</option>
<option>Third Option</option>
<option>Fourth Option</option>
<option>Fifth Option</option>
</select> <br>
</p>
<p><textarea name="mynotes" rows="5" cols="41" wrap="virtual"></textarea></p>

<div class=item>
<table class="mytable" cellspacing=1>
<tr>
<TD><button class="mybutton" type="button"/>Create</TD>
</tr>
</table>
</div>
</form>
</center>
</body>

VIPStephan
05-27-2012, 04:04 PM
You can’t create files with JavaScript, let alone on the users’ computer. The only thing you can do is create a text file through a server side script that you can offer for download. But again, JavaScript has nothing to do with this except the automatic form submission on change.

xelawho
05-27-2012, 04:50 PM
will only work in IE with appropriate permissions:



<!DOCTYPE html>
<html>
<head>
</head>
<body>

<center>
<form name="formb">

<tr>
<td class="label2"><b>Name </b></td>
<TD><input class="textbox" name="cxname"></td>
</tr>

<p><select name="dissue" OnChange="messageReveal()">
<option value="0">Select</option>
<option>First Option</option>
<option>Second Option</option>
<option>Third Option</option>
<option>Fourth Option</option>
<option>Fifth Option</option>
</select> <br>
</p>
<p><textarea name="mynotes" rows="5" cols="41" wrap="virtual"></textarea></p>

<div class=item>
<table class="mytable" cellspacing=1>
<tr>
<TD><button class="mybutton" type="button" onclick="makeFile()"/>Create</TD>
</tr>
</table>
</div>
</form>
</center>

<script type="text/javascript">
function makeFile(){
// initialize ActiveXObject and create an object of Scripting.FileSystemObject.
var fso = new ActiveXObject("Scripting.FileSystemObject");

// Open the text file at the specified location with append mode
var txtFile = fso.OpenTextFile("C:\\file.txt", 8, true, 0);
txtFile.WriteLine(document.formb.cxname.value);
txtFile.WriteLine(document.formb.mynotes.value);
txtFile.Close();
fso = null;
}
<!-- Begin
var messages = new Array(6);
messages[0] = "";
messages[1] = "You selected option 1";
messages[2] = "You selected option 2";
messages[3] = "You selected option 3";
messages[4] = "You selected option 4";
messages[5] = "You selected option 5";
function messageReveal() {
var messageindex = document.formb.dissue.selectedIndex
document.formb.mynotes.value = messages[messageindex];
}
// End -->
</script>


</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum