Solved

How to trigger onclick event in NS4 ?

Posted on 2002-07-23
9
297 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
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
 
LVL 10

Expert Comment

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

0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now