Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-27-2012, 03:55 PM   PM User | #1
mikoto
New to the CF scene

 
Join Date: Nov 2010
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
mikoto is an unknown quantity at this point
HELP: Copy and Save to a notepad onclick

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.


Code:
<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>
mikoto is offline   Reply With Quote
Old 05-27-2012, 04:04 PM   PM User | #2
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,614
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
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.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 05-27-2012, 04:50 PM   PM User | #3
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 454 Times in 452 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
will only work in IE with appropriate permissions:

Code:
<!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>
xelawho is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:17 PM.


Advertisement
Log in to turn off these ads.