0

I have designed a text field with an Add-Email button. On each click I want the text field value to be appended to a file.

A dropdown list is there which will read the data from the file and show it to user.

I have implemented the second part to populate the data from the file to the dropdown, but I'm stuck with the first part.

Is this the right way to implement this feature by using file read/write or any alternative is available in JavaScript?

Below is the code what i have tried :

drop down box html :

select name="Email" id="Email" 

function to populate the file data to drop down :

    <script>
        $.getJSON("C:/test.txt", function( json ) {
           $.each(json, function(key, value) {
              $('select[name=Email]').append('<option value="' + value + '">' + json[key] + '</option>');
           });
        });
    </script>

text file :

 {
    "Key1": "Test1",
    "Key2": "Test2",
    "Key3": "Test3",
    "Key4": "Test4"
 }

input text filed :

input id="Email_store" type="text"

Button :

button id=Add_Email onclick="saveEMail()"

Now what i want is when a user enters any value in the text field and clicks on the save button, the data should be appended to the file without replacing the existing values in the file.

Botimoo
  • 599
  • 6
  • 16
user8113638
  • 3
  • 1
  • 1
  • 4
  • It is possible to write to file at local filesystem, though not using ajax alone – guest271314 Jun 06 '17 at 04:55
  • @guest271314 Hi, I tried all the suggested links u have provided but i am not getting how i can append my text field values which is JSON format, Please help, i am new to JS. or is there any other way i can try it. – user8113638 Jun 06 '17 at 05:43
  • What do you mean? You can use `` element to upload file. Edit file at ` – guest271314 Jun 06 '17 at 05:46
  • See [Save JSON data to text file and read it](https://stackoverflow.com/questions/44038201/save-json-data-to-text-file-and-read-it/44038992#44038992) – guest271314 Jun 06 '17 at 05:51
  • @guest271314 I mean is this the right way to implement this feature using file read/write or any other alternative i can do for the same. – user8113638 Jun 06 '17 at 05:51
  • What is "the right way"? According to? – guest271314 Jun 06 '17 at 05:52
  • @guest271314 1 As currently i am trying to write the text field input to a file and populating the drop down box by using file read. I mean apart from File read write, can i implement this in any other way in js?? – user8113638 Jun 06 '17 at 06:03
  • What do you mean by "any other way"? That is a quite broad inquiry. Though links provide several different ways of achieving requirement. Does link at previous comment not perform expected task? – guest271314 Jun 06 '17 at 06:08
  • @guest271314 Thanks a lot, Below link helped (https://stackoverflow.com/questions/34034475/edit-and-save-a-file-locally-with-js) I have one question in this case i am able to modify and download the existing file but the modified file is getting saved in download folder and its appending 1 to the file name so how can i make it working. I just want to modify the existing file and save it in same location. – user8113638 Jun 06 '17 at 13:10
  • You can change the directory and name of the file at `Save File` prompt dialog. At settings select `Ask where to save each file before downloading` – guest271314 Jun 06 '17 at 14:08

0 Answers0