Forum Moderators: open

Message Too Old, No Replies

onclick function calls

Trying to learn how to call multiple functions from a strange onclick setup

         

i9design

6:37 pm on Sep 30, 2010 (gmt 0)

10+ Year Member



This is the code that is part of a Star Rating System. I simply want to also call a function called showall() along with the strange code called by onclick below. Please help. Thank you!


this.element.onclick = function () {this.parent.set(this.index)}.bind(this);

is the line I am trying to make also call the function showall(); I have commented out my solution that does not work.

var SingleStar = Class.create();
SingleStar.prototype = {
initialize: function(parent, index) {
this.parent = parent;
this.index = index;
if(debug) console.log('Creating star at index '+ this.index);
this.value = this.index * this.parent.options.multiplier;
if(debug) console.log('value '+ this.value);
this.element = document.createElement("div");
this.element.style.width = this.parent.options.width + "px";
this.element.style.height = this.parent.options.height + "px";
this.element.style.backgroundImage = "url(" + this.parent.options.sprite + ")";
this.element.style.backgroundPosition = (this.index == 0) ? "0 -" + this.parent.options.height * 3 +"px" : "0 0";
this.element.className = "standard_star";
this.element.style.cssFloat = this.parent.options.align;
if(!this.parent.options.showNull && this.index == 0) this.element.style.display = "none";

//
// this.element.onclick = handleclick (parent, index);
// LINE BELOW IS THE CODE I CANNOT FIGURE OUT

this.element.onclick = function () {this.parent.set(this.index)}.bind(this);
this.element.onmouseover = function() { this.parent.show(this.index); }.bind(this);
this.element.onmouseout = this.parent.reset.bind(this.parent);
if(debug) console.log('set onclick handler');
}
};


// Below is the solution I tried.
<!--
/* function handleclick(parent, index)
{
this.parent = parent;
this.index = index;
this.parent.set(this.index).bind(this);
showall();
return true;
};
*/
-->

Fotiman

7:12 pm on Sep 30, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Welcome to WebmasterWorld!

I simply want to also call a function called showall() along with the strange code called by onclick below.

Have you tried this?

this.element.onclick = function () {this.parent.set(this.index);showall();}.bind(this);

i9design

3:01 am on Oct 1, 2010 (gmt 0)

10+ Year Member



Thanks for the welcome!

And thank you so much for the simple and elegant solution!

Adrian