I'm working with document creation, where the user enters the information so that the document can be generated. I would like that if the user had already typed something in one of the fields and clicked to exit the page, an exit confirmation message appeared on the screen. I gave a read on other topics here and found onbeforeunload of JavaScript , however, I did not find anything talking about how to make the message appear only if there is something in the fields. My code looks like this:
<script language="JavaScript">
window.onbeforeunload = confirmExit;
function confirmExit(){
if((document.getElementsByName("interessado").value != "")||
(document.getElementsByName("assunto").value != "")||
(document.getElementsByName("assinatura").value != "")){
return "Deseja realmente sair?";
}
}
How can I create an output confirmation message only if there is any information in the text fields?