0

I have couple of select tags that generate an array. Until now I was just logging the array on the console when pressing SUBMIT button but now I want to save them on a separate text file.

My main.html:

 <form method="POST" action="/submit">
         <select name="rank" size="1" required >
                    <option value="" selected disabled hidden>Rank</option>
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                    <option value="5">5</option>
                    <option value="6">6</option>
                  </select>
  <div class="submit-holder">
        <input type="submit" value="Submit" name="submit" id="submit"/>
  </div>
 </form>

My app.js:

app.post('/submit', function(req, res){
 console.log(req.body.rank);
});

Thank you very much in advance!

Sarvan Kumar
  • 926
  • 1
  • 11
  • 27
  • 4
    you need to use a backend language for that you cant do that with js – Abslen Char Mar 29 '18 at 15:22
  • 1
    By the looks of `app.post` it seems you are using Node with Express? If you are using Node you can use the [filesystem API](https://nodejs.org/docs/latest/api/fs.html) to write your files. [This](https://stackoverflow.com/questions/2496710/writing-files-in-node-js) post touches on the filesystem API and how to use it. – Wild Beard Mar 29 '18 at 15:32
  • Where do you want to save the text file with the array data? .. And for what purpose? – Asons Mar 29 '18 at 15:39

1 Answers1

1

Take a look at this to save data using blob and FileServer.js: https://redstapler.co/generate-text-file-javascript/

Paul
  • 2,086
  • 1
  • 8
  • 16