Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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>

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,662
    Thanks
    6
    Thanked 1,006 Times in 979 Posts
    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.

  • #3
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,968
    Thanks
    56
    Thanked 557 Times in 554 Posts
    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>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •