Javascript Error On Internet Explorer 6,7,8, " Is Null Or Not An Object "
when I start my index.php it calls my javascript file that has this code below: when the application starts immediately this error appears: and this can only happen on the intern
Solution 1:
Update:
After the updated question - you can test for the element first
functionfocus(){
var txtNameObj = document.getElementById('txtName');
if(txtNameObj){
txtNameObj.focus();
}
}
This should avoid the error with it not being defined.
Original
I can only guess there is one of two problems:
a.) Your DOM hasn't loaded yet (so even though that ID will exist, it doesn't yet)
b.) You do not have an element with that ID.
If the element does exist, be sure to only call the focus function once you are sure that the element is loaded. e.g. you could place it as a script tag just before the body close.
<script>
focus();
</script></body></html>
Solution 2:
Why dont you put a conditional for this method: In this case:
var iId = document.getElementById('txtName');
if(iId != null)
{
// Processing
}
Post a Comment for "Javascript Error On Internet Explorer 6,7,8, " Is Null Or Not An Object ""