0
I am working with creating documents, where the user enters with the information so that the document can be generated. I would like if the user had already written something in any of the fields and clicked to exit the page, an output confirmation message would appear on the screen. I read about other topics here and found out onbeforeunload of Javascript, however, I found nothing talking about how to make the message appear only if there is something in the fields. My code is 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 some information in the text fields?
Just count it, pick it up
input
(ex), and makes alength
, ai if it is larger than one, you warn (call the function), otherwise...– Rafael Augusto
You think you’re more efficient than the method Lucas quoted below?
– Lucas Ramos
I think it doesn’t change much, since the concept is the same, then it will depend on what you think best, I especially usually count, but the two solutions will bring a very similar result
– Rafael Augusto