Form event scope

M

Martin

I am writing a javascript object and once complete i will create an
instance of the object to use in my webpage.

Within the object constructor i create a form with a select list in
it, the form is contained in a DIV element.
I want the select list onChange event to call a method of my object.

So the constructor is:

function PanoramaViewer()
{
// code snipped for clarity
// DIV containing form and select list created
// the form HTML is:
// <form name="indexForm"><select name="indexList"
onChange="call_myEvent"></select><br>Auto-hide index:&nbsp;<input
type="checkbox" name="autoHideIndex" checked disabled></form>

this.myEvent=function() { // some script here; };
}

And i create an instance of my object:

var myViewer=new PanoramaViewer();

As you can see i want the select box onChange event to call the
myEvent function.
How can i do this?

onChange="myEvent()" fails as myEvent() is not found in the scope of
the event call.

onChange="myViewer.myEvent()" works as it directly references the
method of the object instance but obviously i don't want to have the
name of an object instance hardcoded into the constructor.
(It works as a hack but isn't really valid).

I've spent a few days searching for ways to have the onChange event
call the instances' myEvent method but found nothing that helps.

Any ideas?

Thanks a lot.

Martin.

PS I can post more detail if needed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,901
Members
47,439
Latest member
elif2sghost

Latest Threads

Top