Solved

Javascript Event Handlers

Posted on 2009-05-07
8
374 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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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 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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

707 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

13 Experts available now in Live!

Get 1:1 Help Now