homepage Welcome to WebmasterWorld Guest from 54.227.171.163
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
window.onfocus to click a button doesnt work
nil111

5+ Year Member



 
Msg#: 3816046 posted 5:12 am on Dec 30, 2008 (gmt 0)

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!

 

nil111

5+ Year Member



 
Msg#: 3816046 posted 5:14 am on Dec 30, 2008 (gmt 0)

btw document.getElementById('btn').click(); also gives the same error. :(

eelixduppy

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



 
Msg#: 3816046 posted 5:18 am on Dec 30, 2008 (gmt 0)

Are you using separate windows or dealing with all the same window?

nil111

5+ Year Member



 
Msg#: 3816046 posted 5:26 am on Dec 30, 2008 (gmt 0)

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

nil111

5+ Year Member



 
Msg#: 3816046 posted 7:46 am on Dec 30, 2008 (gmt 0)

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. :)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved