Why warning message does not disappear?
In the script if user input contains space ' ' or does not contain @, then get warning.
Problem is that if space is deleted, warning does not disappears. What need to change?
HTML Code:
<script type="text/javascript">
<!--
function checkEmail(email){
if(email.length > 0) {
if (email.indexOf(' ') >= 0)//The indexOf() method returns the position of the first occurrence of a specified value in a string.
document.getElementById('myDiv1').innerHTML = 'email addresses cannot have spaces in them';
else if (email.indexOf('@') == -1)
document.getElementById('myDiv1').innerHTML = 'a valid email address must have an @ in it';
else if (email.indexOf('@') == 1)
document.getElementById('myDiv1').innerHTML = '';
else if (email.indexOf(' ') == 0)
document.getElementById('myDiv1').innerHTML = '';
}
}
//-->
</script>
</head>
<body>
<form action="#" method=post>
email: <INPUT NAME="email" onChange="checkEmail(this.value)"><BR>
</form>
<div id="myDiv1"></div>