Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Event in Frames

Status
Not open for further replies.

greyone

Programmer
Dec 14, 2000
200
CA
I have 2 frames ansd i want to trigger an onclick event on click anywhere in the bottom frame. I have written the following code in the bottom frame but the event is triggered onload instead of onClick. Please help

if (document.all)
document.body.onclick=alert("hello")

 
this is because when you are using an event handler you must specify a function reference, not actually run the function.

function alert_hello()
{
alert("hello")
}

document.body.onclick=alert_hello

notice there are no ()'s - this is a function reference instead of a function call. This way you can dynamically select handlers for your functions. Any code you place on the other side of the = sign is called immediately. In your case, alert() returns true, so there is no error jared@aauser.com
 
actually this if (document.all)
document.body.onclick=alert("hello")
could be used to redefine the onclick event
 
all that will do, is execute alert("hello") immediately and throw an error. I wrote a faq on this recently, check it out. jared@aauser.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top