Solved

Javascript Event Handlers

Posted on 2009-05-07
8
395 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
  • 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
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!

 
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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

685 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