javascript oo: passing object

I want to create a button where you can choose for 5 possibilities.(1-5)
see attach. When onover the choosen 'subbutton'  lights up and when you click the 'light' stays on.

I've created a object button with three objects. the object nfo keeps the onover en clicked situation
With these 2 properties the object rbutton shows een gif (03.gif)

problem: in the function onover I can't change any property of the nfo object or read it.

I know the code is a little messy but I tried a lot of things.

Any ideas?
// JavaScript Document
var knop1 = new button('a',100,100)
function button(nm,x,y){ = nm
	bg = new rbutton(this,x,y)
	nm1 = new sbutton(this,nm+'1',1,x+59,y+12,bg);
	nm2 = new sbutton(this,nm+'2',2,x+71,y+50,bg);
	nm3 = new sbutton(this,nm+'3',3,x+41,y+73,bg);
	nm4 = new sbutton(this,nm+'4',4,x+10,y+50,bg);
	nm5 = new sbutton(this,nm+'5',5,x+21,y+12,bg);
	nfo = new info()
function  info(){
	this.clicked = 0
	this.over = 0
function rbutton(nm,x,y){
    var newNode = document.createElement("div");
    newNode.setAttribute("id", nm);
    newNode.setAttribute("style", "visibility: visible;");
	var deknop = document.getElementById(nm); = "absolute"; = x + "px"; = y + "px";
	info.prototype.setclicked = function(res) {
	nfo.clicked = res
info.prototype.setover = function(res) {
	alert("res: "+res)
	nfo.over = res
	info.prototype.alertClass = function() {
	alert(this.clicked + " " + this.over);
function sbutton(prnt,nm,nr,a,b,bg_){
	//alert(" " + bg_.clicked)
	//p = prnt.getparent(nm)
    var newNode = document.createElement("div");
    newNode.setAttribute("id", nm);
    newNode.setAttribute("style", "visibility: visible;");
	newNode.setAttribute("onmouseover", "onover('" +prnt+"',"+ nr +")");
	newNode.setAttribute("onmouseout", "onover('" +prnt+"',0)");
	newNode.setAttribute("onmousedown","clickit('" +prnt+"',"+nr+")");
	var deknop = document.getElementById(nm); = ""; = "absolute"; = a + "px"; = b + "px"; = "20px"; = "20px";
	deknop.innerHTML = "<span align='center'>&nbsp;&nbsp;"+nr+"&nbsp;&nbsp;</span>";'pointer'
function clickit(nm,nr){
	alert("nr: " +nfo.clicked)
	alert("bg.clicked: " + nfo.clicked)
	alert("over: " +nfo.over)
function onover(nm,nr){
	document.getElementById(nm).innerHTML= "<img border='0px' src='"+ nr + nr + ".png'>"

Open in new window

Who is Participating?
bdbsailorConnect With a Mentor Author Commented:
jwmcpeak:: I changed that
info object nfo is not recognized in function onover, not a problem in function clickit
Change nfo.over = res to this.over = res.
And from looking further, it looks like setClicked and setOver suffer from the same problem: nfo doesn't exist in their scope. Change nfo to this in both of those methods, and it should work.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.