Welcome to WebmasterWorld Guest from 54.162.240.235

Forum Moderators: open

Message Too Old, No Replies

window.onfocus to click a button doesnt work

     
5:12 am on Dec 30, 2008 (gmt 0)

5+ Year Member



Wat I want to do is get the button 'btn'(this is both the id & name of the button) clicked when the particular file is opening.

I have the following code in my file.

window.onfocus =window.document.getElementById('btn').click();

but I get the error:

window.document.getElementById("btn") is null

but, I checked and the there's no spelling mistakes and wel of coz the button do exist :)

pls help me out to find wats wron. thanks in advance!

5:14 am on Dec 30, 2008 (gmt 0)

5+ Year Member



btw document.getElementById('btn').click(); also gives the same error. :(
5:18 am on Dec 30, 2008 (gmt 0)

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 5+ Year Member



Are you using separate windows or dealing with all the same window?
5:26 am on Dec 30, 2008 (gmt 0)

5+ Year Member



this is a pop up window. in this pop up window there is a button. i want that to get clicked wen the window is loadin. I put it inside the body onload function and it works(but that way I dnt get sm other functionality workin). so I was wonderin whether any other way was possible. thanks 4 the reply
7:46 am on Dec 30, 2008 (gmt 0)

5+ Year Member



solved it! thanks eelixduppy for tryin to help. wel the problem was with the javascript. the error is generated coz onFocus of the window the javascript was still not loaded. thats why it worked with onLoad. I solved this by using onMouseOver. since the javascript is loaded at that time it works perfectly. :)
 

Featured Threads

Hot Threads This Week

Hot Threads This Month