2

I trying do a small app for getting information about hardware in our small office. It is probably very simple but today isn't my best day.

So I have something like this:

<form>
<input type="text" name="namePC" id="namePC">
<select name="keyboard">
    <option value="Dell">Dell</option>
    <option value="Genius">Genius</option>
    <option value="Logitech">Logitech</option>
</select>
<select name="Mouse">
    <option value="Genius">Genius</option>
    <option value="A4tech">A4tech</option>
    <option value="Logitech">Logitech</option>
</select>
<button onclick="do_magic()">Write</button>
</form>

and I need to write a script in JavaScript which takes this data and writes into the XML file.

<pc>
<namePC></namePC>
<keyboard></keyboard>
<mouse></mouse>
</pc>

Can anyone help? Small example about grabbing data and writing into the XML, should be enough.

Adam Michalik
  • 9,678
  • 13
  • 71
  • 102
Arten
  • 21
  • 1

1 Answers1

0

Javascript, in and of itself, can not write files. This is done so that you cannot accidentally be "hacked" by browsing to a page and it automatically downloads/writes a virus onto your system. Really, it's a well thought out example of security coming before anything else.

With this in mind, you will need to use AJAX to send the request out to a server side language (PHP, Java, Ruby, etc), and from THERE you can write to a file, on that server or on a network location that's shared and it has permissions on. Doing it as is though is not possible in and of itself.

If you wish to generate the file one after the other and then later append the data to create your one file, that may work as discussed in the linked question, but obviously I doubt that this is the intended, or even plausible solution given the amount of human time/resources needed, as well as the chance for error.

Relevant question: Is it possible to write data to file using only JavaScript?

Community
  • 1
  • 1
Gyhth
  • 1,155
  • 9
  • 21