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

19th Feb 2025, 4:47 PM
Honza Horák
Honza Horák - avatar
4 Antworten
+ 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>
20th Feb 2025, 10:34 AM
Bob_Li
Bob_Li - avatar
+ 8
Per default, some browsers clear the page when the submit event is triggered.
19th Feb 2025, 5:54 PM
Lisa
Lisa - avatar
+ 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.
19th Feb 2025, 5:03 PM
Ausgrindtube
Ausgrindtube - avatar
+ 2
Honza Horák Honzo, zkus preventDefault ()
19th Feb 2025, 7:59 PM
r8w9
r8w9 - avatar