Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to write text field values into a text file before form submission using javascript

I'm new to Java script.

I'm implementing some web pages.
Now, i have TextBox fileds (for users to enter server ip,username and password),upload file button and a Submit button .i want to call a Javascipt script function which takes the values from the textbox and saves it to a .txt file on server before clicking submit button.

Using java script I'm able to read values but when I'm trying to write values into a file, it is not working. When i searched in net i found solution with ActiveXObject which workes only in IE.But I'm looking for the solution which works in all browsers.

My environment supports only javascript and PHP.

Please help me..

like image 605
Sai Avatar asked Dec 12 '25 21:12

Sai


1 Answers

<form id="addnew">
    <input type="text" class="id">
    <input type="text" class="content">
    <input type="submit" value="Add">
</form>
<script>
    jQuery(function($) {
        $('#form_addjts').submit(function(){
            writeToFile({
                id: $(this).find('.id').val(), 
                content: $(this).find('.content').val()
            });
            return false;
        }); 
        function writeToFile(data){
            var fso = new ActiveXObject("Scripting.FileSystemObject");
            var fh = fso.OpenTextFile("D:\\data.txt", 8);
            fh.WriteLine(data.id + ',' + data.content);
            fh.Close(); 
        } 
    }); 
</script>
like image 64
vikram mistry Avatar answered Dec 15 '25 10:12

vikram mistry