/    Sign up×
Community /Pin to ProfileBookmark

help class problem

hi!

I’m trying to create class with all necesery methods for slide bar graphic element.

the problem is whenever i create new instance of that class i lose all event listeners for other instances of the same class…
Actualy all i know is that only last instance is event sensitive.
here is the script… it should only alert a message when mouse button is presed in the slider area ?.

any ideas?

thx!

btw sorry for my bed english ?

doc=document;
function sliderbar(parentdocid,pozx,pozy,maxvalue,size,slidername)
{
var poz=0;

this.slidersize=size/25;
this.htmlcod=slidername;
this.htmlcod+=”<div id=””+slidername+”” style=”border: black thin solid; position:relative; left:”+pozx+”px; top:”+pozy+”px; width:”+size+”px; height:20px;” onmouseover=”javascript:mover(event);”>”;
this.htmlcod+=”<div id=”+slidername+”slide style=” position:absolut; background-color:grey; width:”+this.slidersize+”px; height:20px;”></div></div>”;

this.parent=doc.getElementById(parentdocid);
this.parent.innerHTML+=this.htmlcod;
this.sliderbar=doc.getElementById(slidername);
this.slider=doc.getElementById(slidername+”slide”);

while(this.slider.offsetParent)
{
this.poz += this.slider.offsetLeft;
this.slider=this.slider.offsetParent;
}
this.slider=doc.getElementById(slidername+”slide”);
this.grab=function()
{
alert(poz);
}
this.move=function()
{
}
this.drop=function()
{
}
this.sliderbar.addEventListener(“mousedown”,this.grab,true);
return;

}
var slider1=new sliderbar(“formsettings”,55,-20,255,150,”RED”);
var slider2=new sliderbar(“formsettings”,55,-20,255,150,”GREEN”);
var slider3=new sliderbar(“formsettings”,55,-20,255,150,”BLUE”);

html part
<div id=”formsettings” class=”settings”></div>

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@patuljakauthorSep 29.2007 — please say that what i am trying to do is noncence if you think so ?.

i can"t sove my problem and it's realy enoying...
Copy linkTweet thisAlerts:
@KravvitzSep 30.2007 — Perhaps these will help:

[url=http://www.digital-web.com/articles/objectifying_javascript/]Objectifying JavaScript[/url]

[url=http://www.digital-web.com/articles/scope_in_javascript/]Scope in JavaScript[/url]
Copy linkTweet thisAlerts:
@patuljakauthorSep 30.2007 — well thx for that two links that was part of the problem... but i solved this problem with adding var handler=this in my constructor function... yes it is a bit rough but it is working. There is a complitly working example here http://www.webdeveloper.com/forum/showthread.php?t=162010

complitly except that only the last instance is working... if there is only one it is working... but if you add the second instance then first stop working... and so on...
Copy linkTweet thisAlerts:
@KravvitzSep 30.2007 — I missed it last night...

The problem is that the event handlers are lost when you change the innerHTML property of the parent of the elements.

You should use document.createElement() and appendChild() instead of innerHTML.

P.S. Next time please don't start multiple threads about the same problem.
Copy linkTweet thisAlerts:
@patuljakauthorSep 30.2007 — THX very much... and sorry about multiple Threads
×

Success!

Help @patuljak spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...