简体   繁体   中英

How to remove the alert message while user is typing on keyboard by jQuery?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Save new student</title>
<script>

function insertdata()
{

var n = document.getElementById("name").value;
var f = document.getElementById("family").value;
var m = document.getElementById("mark").value;
var t = document.getElementById("tell").value;

 if ((n=="") || (f=="") || (m=="") || (t=="")){


  var error=document.getElementById("error").innerHTML="fill out the form with valid values";

 }
 **else if()**
 {


 }
 else{

frminsert.submit();


 }

 }


</script>
</head>

<body>

please enter your data:

<br/>

 <form action="saveinsert.php" method="post" name="frminsert">
  Name :
 <input type="text" name="name" id="name" />
 <br/>
 Family :
 <input type="text" name="family" id="family" />
 <br/>
 Mark :
<input type="text" name="mark" id="mark" />
<br/>
 Tell :
<input type="text" name="tell" id="tell" />
<br />
 <input type="button" value="Save New Student"  onclick="insertdata();" />

 <input type="reset" value="Reset Form" />

</form>
<p id="error"></p>
<a href="show.php">show the list of students</a>
</body>
</html>


My code will indicate the error message with this statement : Fill out the form properly.
I'm going to elaborate it more , I need to eliminate the error message which is mentioned above , when user start to type on keyboard.

I think this is what you need? (Clearing the error message)

document.getElementById("error").innerHTML= "";

If you want it to happen when the user does something, like types into a box then you'll need to add an event listener on to that input something like

<input onKeyDown="removeErrorMessage()" ... />
...
<script>
function removeErrorMessage{
document.getElementById("error").innerHTML= "";
};
</script>

You can put this into first line:

function cleanError()
{
document.getElementById("error").innerHTML= "";
}

And each input put onBlur="cleanError() " like this:

<input onBlur="cleanError()" type="text" name="family" id="family" />

Good Luck !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM