1
<!DOCTYPE html>
<html>

<head>
  <script>
    function loginButtonClick() {
      var Refresh = document.forms.form1.refresh.value;
      alert(Refresh);

      var Area = document.forms.form1.area.value;
      alert(Ticks);
    }
  </script>
</head>

<body>
  <form id="form1">
    Refresh:
    <br>
    <input id="refresh" type="number" name="Refresh" value="">
    <br>
    <br> area:

    <br>
    <input id="area" type="number" name="area1" value="">
    <br>
    <br>

    <input type="submit" value="Submit" onclick="loginButtonClick()">

  </form>
</body>

How can I save the Refresh and Area values to a JSON file as an array with the following format?

 data = '[{"Refresh" : 100, "area": 10}]';
twernt
  • 20,271
  • 5
  • 32
  • 41
joe
  • 21
  • 1
  • 5
  • 6
    What do you mean stored in a JSON file? You want to write to a file? JavaScript is really limited on that front. Look into `JSON.stringify()` – epascarello Feb 01 '16 at 14:18
  • Possible duplicate of [Writing a json object to a text file in javascript](http://stackoverflow.com/questions/22055598/writing-a-json-object-to-a-text-file-in-javascript) – Daniel Higueras Feb 01 '16 at 14:21
  • For one do not use the click event, but use the form's submit event and return false if you do not want to actually submit the form – mplungjan Feb 01 '16 at 14:22
  • What are you trying to achieve? Why would you want to write that to a file? what should happen with this file? ... – Thomas Feb 01 '16 at 14:29
  • Where does this json file live? – epascarello Feb 01 '16 at 14:31
  • Clientside JavaScript can not write to your server. – epascarello Feb 01 '16 at 14:35
  • js in the browser has no access to your local filesystem. You have to take the roundtrip through a server. (this can be a locally hosted apache or node or whatever) What are you building here? What is the reason of this local html-file? – Thomas Feb 01 '16 at 14:41
  • then you already have a backend. Create a route that takes these vlaues as form-values and writes them to the file. And in the frontend it can be a simple form-submit. Maybe you want to restrict this route to the localhost or local Network. – Thomas Feb 01 '16 at 14:56

0 Answers0