0
Why does it disappear?
In the code bellow, i programmed an app where you can send messages. But when i click the send button, the whole entire page disappears. Can someone please explain? I and chatgpt have no clue. https://sololearn.com/compiler-playground/W6bfbvoSqV8h/?ref=app
4 ответов
+ 4
don't use form.
as Lisa said, clicking on a button nested inside form tags  will default to a submit action and it will refresh your page resulting in a blank page in Sololearn.
you can test it by just only writing this in your html tab:
<form><button>click me</button></form>
clicking the button will clear your page. The button will disappear...
clear your js tab and copy-paste this on your html tab:
<!DOCTYPE html>
<html>
<head>
  <title>Message For Yourself</title>
</head>
<body>
  
  <table id="list"></table>
        
  <input type="text" id="text">
  <button onclick="submit()">/\</button>
  
  <script>
  const input =  document.getElementById("text");
        
  function submit() {
    let text = input.value;
    if(text) {
      input.value = "";
      let table = document.getElementById("list");
      let row = table.insertRow(-1);
      let cell1 = row.insertCell(0);
      cell1.innerHTML = text;
    }
  }
  </script>
</body>
</html>
+ 8
Per default, some browsers clear the page when the submit event is triggered.
+ 4
Does it disappear on your other IDE/Computer/Browser? Or only on Sololearn?
I'm pretty sure Sololearn has limited functions and sending a message wouldn't be something the code playground can do.
+ 2
Honza Horák Honzo, zkus preventDefault ()








