Solved

Javascript Event Handlers

Posted on 2009-05-07
8
402 Views
Last Modified: 2012-05-06
I am quite inexperienced with Javascript. So this is probably an easy question for you experienced web developers. I have an ActiveX object that I am loading in a web page.

HTML ActiveX Object tag:

<object id="CWButton1" classid="CLSID:d940e4be-6079-11ce-88cb-0020af6845f6" codebase="cwui.ocx" style="width:100px; height:100px; Left:200px; Top:50px; position:Absolute;"><PARAM NAME="empty" VALUE="0"/></Object>

After I load the object, I run a javascript function that sets the attributes of the activex button. I would like to add an event handler to the activex button using javascript, but so far am having trouble getting it work. I am quite new to Javascript.

I'm not sure why the the developers at national instruments didn't use the standard button "Click" event, but they didn't instead they disabled that event and created an event named "ClickEvent". ClickEvent has two parameters, sender and eventargs.

Here is what I have tried, but it doesn't work:

function ApplyButtonSettings(params) {
 var btn = document.getElementById('CWButton1');
 ...
 btn.addEventListener("ClickEvent", "Test");
}

function Test(sender, args){
 alert('hello');
}

Any help would be appreciated. Thanks.

Troy
0
Comment
Question by:tdyck12345
[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
  • 4
  • 4
8 Comments
 
LVL 13

Assisted Solution

by:Onthrax
Onthrax earned 20 total points
ID: 24330698
Been a while since I used the addEventListener, but I think I always used 'click' or 'onClick' and not ClickEvent (also javascript is case sensitive, so watch out with that)...
0
 
LVL 2

Author Comment

by:tdyck12345
ID: 24331334
Hi Onthrax. Thanks for the reply. I have tried to use the onClick event, but it doesn't work because for some reason the people at NI have overridden the click event to do nothing and then created a custom click event named "ClickEvent." So I need to figure out how to handle this custom event.
0
 
LVL 13

Expert Comment

by:Onthrax
ID: 24334222
Ah I misunderstood. My apologies.

I have never used an eventlistener on a custom event, but I don't see why your code wouldn't work. it could perhaps be something simple like an invalid call to your ApplyButtonSettings function, which would not fire up the listener...
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 2

Author Comment

by:tdyck12345
ID: 24337057
I have verified that the ApplyButtonSettings function is getting called correctly. I apply a bunch of button settings within that function and the settings all get applied correctly.

When I use addEventListener, I get an error that object does not support the method. But I don't know what the correct method for adding an event listener is.
0
 
LVL 13

Expert Comment

by:Onthrax
ID: 24347828
You are doing this correctly. The event should be attached to the element initiating the event, which in your case would be CWButton1.

The only thing I can think of is a javascript error in your code that gets triggered before the eventlistener. When javascript triggers an unhandled exception, most of the code after that will not be executed.

If you have firefox installed you can easily see if you have a javascript error. Open up the browser and fire up the page. Goto Tools - Error Console (or press ctrl-shift-j). Refresh your page. If any exceptions are thrown they will show up in that console.
0
 
LVL 2

Author Comment

by:tdyck12345
ID: 24355373
I am using IE and don't have firefox installed. But with IE I can see that all the code in ApplyButtonSettings executes without any errors.

But when I add the line

btn.addEventListener("ClickEvent", "Test");

then I get the "object does not support the method" error.
0
 
LVL 2

Accepted Solution

by:
tdyck12345 earned 0 total points
ID: 24365564
I have worked several days and tried all sorts of ways of capturing mouse button clicks on the ActiveX control, but nothing has worked. It seems so strange that there isn't a way to get this working.

Onthrax thanks for your attempts at helping me. I posted this solution twice and you were the only one who even tried to help. The first post when unanswered. I think Experts Exchange should change its name, because there aren't many people on here that are willing to help anyone out. It seems that most people only answer easy questions. Maybe it should be called the beginners exchange. When I look at my question history, over half of my questions were ignored and I ended up coming up with a solution on my own.

This time I came up with a kludge.

The solution I came up with is to capture mouse clicks on the form and then do a hit test on the activex control to figure out which button was clicked. Seems to work so far.
0
 
LVL 13

Expert Comment

by:Onthrax
ID: 24372044
I'm sorry we couldn't find you a solution to the eventlistener, but I'm glad you resolved it on your own.

Good luck m8.
0

Featured Post

Industry Leaders: 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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

738 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