I am trying to bind a click event to some element using jQuery. Using prototype I know I can do this using BindAsEventListener().
Example:
var myObject = {
init: function(txtOneId, txtTwoId, lblResultId, ancAddId) {
this.txtOneId = txtOneId;
this.txtTwoId = txtTwoId;
this.lblResultId = lblResultId;
this.ancAddId = ancAddId;
var addListener = this.addResult.bindAsEventListener(this);
Event.observe(this.txtOneId, 'keyup', addListener);
Event.observe(this.txtTwoId, 'keyup', addListener);
},
addResult: function() {
var valueOne = $(this.txtOneId).value;
var valueTwo = $(this.txtTwoId).value;
if (isNaN(valueOne) || valueOne == "")
valueOne = 0;
else
valueOne = parseInt(valueOne);
if (isNaN(valueTwo) || valueTwo == "")
valueTwo = 0;
else
valueTwo = parseInt(valueTwo);
var result = valueOne + valueTwo;
$(this.lblResultId).innerHTML = result;
return false;
}};