i have made a very basic and simple code in which i have an input field which is validated on every keypress but when i enter anything in the form nothing happens , when i tried the chrome developers this was the error "Cannot set property 'innerHTML' of null Error"
i don't get what am i doing wrong ,i know "document.getElementbyId('show')" returns null but why? someone help please! thank u
this is my index.html file
<script type="text/javascript">
var xmlHttp = new XMLHttpRequest();
function validate(user){
xmlHttp.open("GET", "names.php?name="+user, true);
xmlHttp.onreadystatechange = function(){
document.write("error");
document.getElementById('show').innerHTML = xmlHttp.responseText;
}
xmlHttp.send(null);
}
<h2>Enter a name :</h2>
<form>
<input type="text" onkeypress="validate(this.value)" />
<div id="show"></div>
</form>