Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to trigger onclick event in NS4 ?

Posted on 2002-07-23
9
Medium Priority
?
305 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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
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 800 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

715 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