Is it possible to set the FOCUS() dynamically with javascript
hi,
Code:
<html>
<head>
<script language="JavaScript">
function checkme(strVal){
var id=strVal;
alert(id);
//document.all[strVal].focus();---->(IE) FOR IE it is working but not working for mozilla firefox
document.forms[strVal].focus(); //(FIREFOX)
}
</script>
</head>
<body>
<form>
NAME..<input type="text" name="empName" size="5" maxlength="4" onChange="checkme(this.value)"/><br>
ID....<input type="text" name="id" value=""/><br>
DEPT..<input type="text" name="dept" value=""/><br>
</form>
</body>
</html>
Last edited by AJAY KUMAR; July 6th, 2007 at 12:35 AM..
Re: Is it possible to set the FOCUS() dynamically with javascript
Correct me if I'm wrong, but it appears that you are trying to set the focus in a textfield that maybe a username or something along those lines. IMO the best thing to do would be to use getElementById and set the focus that way. You could put it in a function and use the onload event handler in your body tag.
Code:
function selectField() {
document.getElementById("id of testfield").focus()
}