One of the functions I wrote involves setting the innerHTML of a particular span with the id "mail_not_valid" to display a message when a user attempts to submit an invalid email address. This function works as intended. Additionally, another function is set to clear the input field upon onfocus trigger. A third function triggered by onblur resets the input field to its original value if nothing new was entered. However, a problem arises when a user clicks on the field (clearing it), enters an invalid email (span displays error), and then deletes their entry before leaving the form; in this scenario, the span remains visible.
I attempted replacing document.getElementById("mail_not_valid").innerHTML = ""; with an alert, which did work. Surprisingly, changing the innerHTML directly does not have the desired effect.
EDIT: Upon further examination, I realized my mistake – the function cannot successfully execute if the user had already entered information: if (!(feld.value))
<input onblur="OnBlurCondition (this, 'subscribe to the e-mail newsletter')">
<script language="javascript">
function OnBlurCondition (feld, inhalt) {
if (!(feld.value)){
feld.value = inhalt;
if (document.getElementById("mail_not_valid").innerHTML == "that doesn't seem right."){
document.getElementById("mail_not_valid").innerHTML = "";
}
}
}
</script>