0

My html code

<form id="form">
      <input type="text" class="search" id="search">
      <input type="submit" value="Submit" class="submit">

      <ul><li id="first"></li></ul>
</form>

My Javascript code

document.getElementById("form").onsubmit = function() {Search()};

var itemListVal = "";

isChanged = false;

function Search() {
    let inputValue = document.getElementById("search").value;
    document.querySelector("#first").innerText = inputValue;
    
    itemListVal = inputValue;
    isChanged = true;
}

I was trying to make the item list which I was gonna make as a search history (I am new to frontend developing so I am not trying to storing yet ig) to change as the last searched thing aka the last submitted but It only changes for a really little bit of time and goes back as it is

j08691
  • 204,283
  • 31
  • 260
  • 272
  • 1
    Are you trying to prevent the form from submitting to the server and reloading the page? – David Jul 12 '23 at 14:18
  • 1
    Submit Buttons Submit Forms. You don't cancel the form submission....The form submits and reloads the page. – epascarello Jul 12 '23 at 14:20
  • @David I am not trying to reload the page ig, and I didn't understand what you meant by submitting to the server, thanks though – Mosaab Matar Jul 12 '23 at 14:27

0 Answers0