Вот наглядный пример
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="windows-1251">
<style>
</style>
</head>
<body>
<script>
input=document.createElement("input")
input.onblur=function(){this.style.background="red"}
input.onfocus=function(){this.style.background="blue"}
input.style.color="white"
focusOn=document.createElement("button")
focusOff=document.createElement("button")
focusOn.innerHTML="focus on"
focusOff.innerHTML="focus off"
document.body.appendChild(input)
document.body.appendChild(focusOn)
document.body.appendChild(focusOff)
focusOn.onclick=function(){
input.focus()
}
focusOff.onclick=function(){
input.blur()
}
</script>
</body>
</html>