Wrox Programmer Forums
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 27th, 2008, 08:07 AM
Authorized User
 
Join Date: Oct 2003
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
Default Generate onclick event

Hi,

I have a link and I need to force the onclick event. I need to say that the link was clicked even if the user didn't physically click the link.
Is this possible?

Thanks

 
Old May 27th, 2008, 08:14 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

If the link has an onclick handler defined then you can get a reference to the link using document.links or document.getElementById and then call lnk.onclick().

--

Joe (Microsoft MVP - XML)
 
Old May 27th, 2008, 08:30 AM
Authorized User
 
Join Date: Oct 2003
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

Thanks for the response.
Do you mean if the link is something like this:
<a href="http://p2p.wrox.com" onclick=window.open("http://p2p.wrox.com")>wrox</a>

If that is what you mean then the answer is no it doesn't have an event handler.
What can I do to generate the event?
Thanks

 
Old May 27th, 2008, 09:18 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

No, that's okay. But as the element doesn't have an ID you may need to loop through document.links until you find the one you need.

--

Joe (Microsoft MVP - XML)
 
Old May 27th, 2008, 09:22 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hi collie!!

Another approach could be :
1>get the id of href.
2>attach onclick event at runtime
2>call the onclick event of that href that is attached in step 2.

Hope this will help you


Cheers :)

vinod





Similar Threads
Thread Thread Starter Forum Replies Last Post
onClick event not working !!! muklee Javascript How-To 14 June 4th, 2008 04:08 PM
onclick event bjackman Access 6 July 15th, 2004 06:54 AM
onclick event pigtail Javascript 1 April 11th, 2004 03:10 PM
onClick Event mateenmohd Javascript 4 December 16th, 2003 01:08 AM
onclick event not working? mumps Javascript 2 September 15th, 2003 10:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.