body
isn't defined - you probably mean document.body
or document.getElementsByTagName('body')[0]
- see this jsFiddle: http://jsfiddle.net/LrrpM/
<html>
<head>
<title>ask9</title>
<script>
function changeColor() {
var x=document.getElementById("box").value;
if(isNaN(x)==false)
{
document.body.style.backgroundColor="yellow";
}
else if(isNaN(x)==true)
{
document.body.style.backgroundColor="green";
}
/* // will never occur, isNaN() always returns a boolean
else
{
document.body.style.backgroundColor="red";
}*/
}
</script>
</head>
<body>
<input type="text" id="box" onchange="changeColor()">
</body>
</html>