Solved

How to trigger onclick event in NS4 ?

Posted on 2002-07-23
9
303 Views
Last Modified: 2007-11-27
Hi,

I have in my page a "A" tag with an onclick event associated.  I would like to programatically trigger this onclick event.  I do that with the following block of code. It works with IE but not with netscape 4. When i try that code with netscape 4 I have the following error message "mnuTop_2 has no properties !"
Thanks in advance.

Guillaume.


if (ns4==1)
{
   obj = document.layers["divSlideCont"]
   obj = obj.layers["divSlide1"]          
   obj.mnuTop_2.onclick()
}
else
{
   sName = "mnuTop_" + num
   document.all(sName).onclick()
}
0
Comment
Question by:anderlecht
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 22

Expert Comment

by:CJ_S
ID: 7171537
obj.document.links[0].onclick()

CJ
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 7171538
with 0 being the index of that link.

CJ
0
 

Author Comment

by:anderlecht
ID: 7173691
It seems that it is impossible to trigger programatically the onclick event in NS4 !
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 10

Expert Comment

by:zvonko
ID: 7173737
Does this event you try to fire by script react to real mouse clicks?

0
 

Author Comment

by:anderlecht
ID: 7173762
Yes, when i click on my link it works
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 7173775
Check this script:

<html>
 <head>
 
 </head>
 
 <body>
  <a href="" onClick="alert('link 1 clicked');return false">Link 1</a>
  <a href="#" onClick="document.links[0].onclick();return false">Fire link 1</a>
 </body>
</html>
0
 
LVL 22

Accepted Solution

by:
CJ_S earned 200 total points
ID: 7173785
or this script for when the link is in a div

<html>
 <head>
  <script language="javascript">
  <!--
   function clickit()
   {
             lObj = document.layers?document.layers["mydiv"].document.links[0]:document.all["link0"];
             if(lObj) lObj.onclick();
   }
  //-->
  </script>
 </head>

 <body>
  <a href="#" onClick="clickit();return false">Fire link 1 in div</a>

  <div id="mydiv" style="position:absolute;visibility:visible;top:200px;left:100px;">
   <a href="" onClick="alert('link 1 clicked');return false" id="link0">Link 1</a>
  </div>
 </body>
</html>
0
 
LVL 12

Expert Comment

by:ahosang
ID: 8330316
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

points to CJ_S
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
ahosang
EE Cleanup Volunteer
0
 

Expert Comment

by:modulo
ID: 8395869
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question