Click to See Complete Forum and Search --> : Detirmining if an element has focus
Hi, I was wondering if there way a way to detirmine if an element has focus or not? I want to use it in an if statement, for example:
if (elem.isFocused()) {
}
does anyone know how to do this?
Thanks!
Ultimater
02-09-2006, 04:30 PM
Something to play with
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html dir="ltr" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="content-style-type" content="text/css">
<meta http-equiv="content-script-type" content="text/javascript">
<title></title>
<style type="text/css">
body {
margin:5px;
background:#ffffff;
color:#000000;
}
</style>
<script type="text/javascript">
onload=function(){
var elem=document.getElementById("myInputField")
elem.isFocused=false;
elem.onfocus=function(){this.isFocused=true}
elem.onblur=function(){this.isFocused=false}
setInterval(
function(){
var elem=document.getElementById("myInputField")
elem.value="elem.isFocused="+elem.isFocused
}
,100
)
}
</script>
</head>
<body>
<div>
<input type="text" id="myInputField" value="" readonly="readonly">
</div>
</body>
</html>