So I have a form in my script, so there are a lot of input tags. When someone writes something in the input and closes the page accidentally, then should appear:
alert("You have to fill the whole form.");
This is my code now:
HTML
<input placeholder="name" />
JAVASCRIPT
window.onbeforeunload = function () {
var input = document.getElementByTagName("input");
if (input.value.length > 0){
alert("You have to fill the whole form.");
}
};
My question is, what am I doing wrong?