www.webdeveloper.com
Results 1 to 9 of 9

Thread: Send Form Data to a text file on hard drive

  1. #1
    Join Date
    Jun 2006
    Location
    Asheboro, NC
    Posts
    3

    Send Form Data to a text file on hard drive

    I found this script that will save form data to a text file on my hard drive.
    It does what I’m looking for except. The only thing I would like to add is the use of radio buttons. If anyone could show me how to do this, it would be greatly appreciated.

    All the fields work fine and saving the info to a file except the radio button
    Selection.

    Below is an example of the output…

    , , , , Software, undefined

    The radio button veritable is undefined and I’m not sure how to correct this.

    Thanks
    Greg
    Code:
    <SCRIPT LANGUAGE='JavaScript'> 
    function WriteToFile() {
     try {
       var fso, s;
    0   fso = new ActiveXObject("Scripting.FileSystemObject");
       s = fso.OpenTextFile("C:\\ietm_data.txt" , 8, 1, -2);   
       s.writeline(document.ietmdata.name.value + ", " +  document.ietmdata.email.value + ", " + 
    
    document.ietmdata.location.value + ", " +  document.ietmdata.comments.value + ", " + 
    document.ietmdata.type.value + ", " +  document.ietmdata.problem.value);
    s.Close();
     }
    catch(err){
      var strErr = 'Error:';
      strErr += '\nNumber:' + err.number;
      strErr += '\nDescription:' + err.description;
      document.write(strErr);
     }
    }
    
    </SCRIPT> 
    <BODY>
    
    <form action="test.hta" method="post" name="ietmdata">
    Name:     <input type = "text" name="name"><br>
    Email: <input type="text" name="email"><br>
    Location: <input type = "text" name="location"><br>
    Comments: <textarea name="comments"> </textarea><br>
    
    Type: <select name="type">
        
         <option value="Software"> Software </option>
         <option value="Hardware"> Hardware </option>
    
    </select>
    
    <br>
    <br>
     <p> 
      Requesting information:<BR> 
    
           <input type="radio" name="problem" value="Option 1"> Option 1<br>
           <input type="radio" name="problem" value="Option 2"> Option 2<br>
    
      </p> 
      <p>
    
    <br>
    <br>
    <br>
    <INPUT TYPE=BUTTON VALUE="Submit Data to Text File" onClick="WriteToFile(this.form)">
    </form>
    Last edited by jedaisoul; 05-01-2014 at 02:22 PM. Reason: code tags added

  2. #2
    Join Date
    Mar 2006
    Posts
    66
    Use list box instead & don't allow multiple selection.
    I've done it, have a look at it
    Code:
    <html>
    
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Name</title>
    <SCRIPT LANGUAGE='JavaScript'> 
    function WriteToFile() {
    try {
    var fso, s;
    fso = new ActiveXObject("Scripting.FileSystemObject");
    s = fso.OpenTextFile("C:\\ietm_data.txt" , 8, 1, -2); 
    s.writeline(document.ietmdata.name.value + ", " + document.ietmdata.email.value + ", " + 
    
    document.ietmdata.location.value + ", " + document.ietmdata.comments.value + ", " + 
    document.ietmdata.type.value + ", " + document.ietmdata.problem.value);
    s.Close();
    
    }
    catch(err){
    var strErr = 'Error:';
    strErr += '\nNumber:' + err.number;
    strErr += '\nDescription:' + err.description;
    document.write(strErr);
    }
    }
    
    </SCRIPT> 
    
    
    </head>
    
    <BODY>
    
    <form action="test.hta" method="post" name="ietmdata" >
    Name: <input type = "text" name="name"><br>
    Email: <input type="text" name="email"><br>
    Location: <input type = "text" name="location"><br>
    Comments: <textarea name="comments"> </textarea><br>
    
    Type: <select name="type" >
    
    <option value="Software"> Software </option>
    <option value="Hardware"> Hardware </option>
    
    </select>
    
    <br>
    <br>
    <p> 
    Requesting information:<BR> 
    
    <select name="problem">
    
    
    <option value="Option1"> Option1</option>
    <option value="Option2"> Option2</option>
    
    </select>
    
    
    </p> 
    <p>
    
    <br>
    <br>
    <br>
    <INPUT TYPE=BUTTON VALUE="Submit Data to Text File" onClick="WriteToFile(this.form)">
    </form>
    
    
    </body>
    
    </html>
    The Dark Knight Strikes Again

  3. #3
    Join Date
    Jun 2006
    Location
    Asheboro, NC
    Posts
    3
    Hi Dark Knight,

    Yes, I used the list boxes in the example also just doesnít give my form the look and feel it needs. There may not be a way around this to use radio buttons, I donít know.

    Thanks for looking at it for me.
    Greg

  4. #4
    Join Date
    Jan 2006
    Location
    I'm in GMT -5
    Posts
    561
    g_lundy:

    Please check your private messages.

  5. #5
    Join Date
    Mar 2006
    Posts
    60
    how about...

    <input type="radio" name="radio" value="Option 1" onclick="getElementById('problem').value=this.value;"> Option 1<br>
    <input type="radio" name="radio" value="Option 2" onclick="getElementById('problem').value=this.value;"> Option 2<br>
    <input type="hidden" name="problem" id="problem">

  6. #6
    Join Date
    Jun 2006
    Location
    Asheboro, NC
    Posts
    3
    Thank's for all your help.
    Working great now.

  7. #7
    Join Date
    Aug 2013
    Posts
    3
    Hi I am new user of Java script. The above is not working properly..

    The output is not saved in text file.

    Please reply the correct code on my below mail.

    Thanks & Regards
    Manish Kumar
    abmanish71@gmail.com

  8. #8
    Join Date
    Aug 2013
    Posts
    3

    Request

    Quote Originally Posted by wasim_@_drushti View Post
    Use list box instead & don't allow multiple selection.
    I've done it, have a look at it
    ======

    Hi
    Above code is working fine but I want to store the data on network drive like "10.11.21.33\Site\data\data.txt"

    Please help me and provide the solution

    Thanking you

    Manish Kumar
    Last edited by jedaisoul; 05-01-2014 at 02:25 PM. Reason: Lengthy quote deleted

  9. #9
    Join Date
    Mar 2012
    Posts
    1,659
    Try "http://10.11.21.33/Site/data/data.txt"

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles