?
Solved

Javascript Event Handlers

Posted on 2009-05-07
8
Medium Priority
?
462 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 80 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
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!

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month17 days, 9 hours left to enroll

831 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