Solution:
Html File:
<html>
<head>
<script type="text/javascript">
function showval(str) {
var xhttp;
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("result").innerHTML = this.responseText;
}
};
xhttp.open("GET", "slip17-p1-q2.php?txt="+str, true);
xhttp.send();
}
</script>
<body>
<form action="">
User name: <input type="text" name="txt" onkeyup="showval(this.value)">
</form>
<div id='result'></div>
</body>
</html>
PHP File:
<?php
$user=$_GET['txt'];
if($user==="")
$str="Enter user name";
else if(strlen($user)<3)
$str="User name is too short";
else
$str="Valid username";
echo $str=== ""? "no suggestion":$str;
?>
0 Comments