Search code examples
htmlinputsubmit

how to left text search in input after submit


I have search input. When I write a number to find something (this is an HTTP request) I have some results but my number from input disappeared. How can I leave it?

     div class="control is-expanded">
          <input
            name="request_id"
            class="input"
            placeholder="Request ID"
          />
        </div>
        <div class="control">
          <input type="submit" name="submit" class="button is-link" />
        </div>

The HTTP request in on the beckent, which I didnt write. I do only frontend. Can I change this or not?


Solution

  • HTML:

    <form method="post" action="" onSubmit="return saveComment();">
        <input type="text" name="request_id" class="input" placeholder="Request ID from Furia" />
        <input type="submit" name="submit" class="button is-link" />
    </form>
    

    JavaScript:

    document.getElementById("request_id").value = localStorage.getItem("comment");
    
    function saveComment() {
        var comment = document.getElementById("request_id").value;
        if (comment == "") {
            alert("Please enter a comment in first!");
            return false;
        }
    
        localStorage.setItem("comment", comment);
        alert("Your comment has been saved!");
    
        location.reload();
        return false;
    }