Dojo Onclick Hello World

postCreate : function(){ this.sendHelReq(); this.actRendered(); }, sendHelReq : function() { dojo.connect(dojo.byId("sendhel"), "onClick", alert("hellow")); }, Why does this load on page enter ? should only be triggerd when "sendhel" button is pushed ?
4 answers

I'm not seeing anywhere in your widget where you are creating that dom node. If you want the location of the click box to be where you placed the widget, try just using:

dojo.connect(this.domNode, "onClick", function() { alert("hello"); });

It'll also make your widget easier to find, if in the Common properties, you add some styling to make the mouse become a pointer when hovering:

cursor: pointer;

alert("hellow") is not a function being passed to the dojo.connect, but it is a statement in itself. You are now basically passing 'undefined' as value to the connect (which is the value of executing alert), but triggered the alert side effect as well. What you need as third argument is:

function() { alert("hellow"); }

If you are wondering what the difference is, try googling the 'first class functions' or 'functions as value' concepts. Heads up: you will probably run into the dynamic scope problem next (everyone starting with non trivial javascript does). Once you wrapped your head around that, the rest is easy :).


googled some artikels and tryed the following:

dojo.connect(dojo.byId("sendhel"), "onClick", function() { alert("hellow"); });

However this does not result in the desierd hellow alert box. Is my syntax correct?


dojo.connect('#mxui_widget_ActionButton_6', "onClick", function() { alert("hello"); });


this is not returning me alert box.

i used HTML snippet widget with javascript option