Solved

Javascript Event Handlers

Posted on 2009-05-07
8
390 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Create animated movies for web page 18 85
Hide Table in merge 3 31
jQuery force form POST 7 45
Character counter breaks after adding EmojiOne Area 4 19
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
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 viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

856 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