Home > Enterprise >  Having trouble extracting HTML form results to a text file. I have been trying for 2 hours but nothi
Having trouble extracting HTML form results to a text file. I have been trying for 2 hours but nothi

Time:06-02

Like I said in the title, I am trying to get my results from the form below:

<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" href="style.css">
  <script>
/* Struggling with this part */
  </script>
</head>
<body>
<h1 style="color:#e6e8e8">Video Game Form</h1>
<form id="form" >
  <div class = "form-control">
    <label>All Time Favorite Game:</label>
    <input name="allgame" id="allgame" type="text" placeholder="Enter your favorite game">
    <label>Favorite Free Game:</label>
    <select name="freegame" id ="freegame">
      <option>Select your favorite game</option>
      <option>Fortnite</option>
      <option>Apex Legends</option>
      <option>Call of Duty: Warzone</option>
      <option>Valorant</option>
      <option>Rocket League</option>
    </select>
  </div>
  <div >
    <label>More games you may play
        <small>(Check all that apply)</small>
    </label>
    <label>
        <input type="checkbox"
            name="inp">Minecraft</input></label>
    <label>
        <input type="checkbox"
            name="inp">GTA 5</input></label>
    <label>
        <input type="checkbox"
            name="inp">Call Of Duty</input></label>
    <label>
        <input type="checkbox"
            name="inp">Fortnite</input></label>
    <label>
        <input type="checkbox"
            name="inp">Valorant</input></label>
    <label>
        <input type="checkbox"
            name="inp">League of Legends</input></label>
    <label>
        <input type="checkbox"
            name="inp">Rocket League</input></label>
    <label>
        <input type="checkbox"
            name="inp">Elden Ring</input></label>
    <label>
        <input type="checkbox"
            name="inp">Zelda</input></label>
    <label>
        <input type="checkbox"
            name="inp">Other...</input></label>
        </div>
  <button type="submit" value="button" >
    Submit
  </button>
</form>
</body>
</html>

It is a basic form I am working on learning web dev, however I am stuck here. If someone wouldnt mind helping me take the results and add it to a text file in the same directory as the HTML and CSS it would be greatly appriciated.

CodePudding user response:

In your <script> tag, you'll either need to add an action for the form or manually get the value of each input element when the select button is clicked. However, in order to write the result to a text file, you'll need something on the server-side. Client-side JS does not provide the utilities to write to server-side files, for this would be impossible to implement.

  • Related