<input id="myElement" type="text" value="" onfocus="this.focused=true;" onblur="this.focused=false;"> <script> if(document.getElementById('myElement').focused) ...; else ...; </script>