473,487 Members | 2,680 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Form event scope

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.

Apr 25 '07 #1
2 1290
Martin wrote:

Hi Martin,

<snip>
I've spent a few days searching for ways to have the onChange event
call the instances' myEvent method but found nothing that helps.
There are many ways to do that, Richard Cornford has described an
interesting pattern using closures, check the "associateObjWithEvent"
example in the following article.

<URL:http://www.jibbering.com/faq/faq_notes/closures.html#clObjI>
Kind regards,
Elegie.
Apr 25 '07 #2
On 25 Apr, 15:28, Elegie <ele...@invalid.comwrote:
Martin wrote:

Hi Martin,

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

There are many ways to do that, Richard Cornford has described an
interesting pattern using closures, check the "associateObjWithEvent"
example in the following article.

<URL:http://www.jibbering.com/faq/faq_notes/closures.html#clObjI>

Kind regards,
Elegie.
Thanks a lot for the link.

It looks like fairly advanced stuff but i'll see what sense i can make
out of it!

Martin.

Apr 26 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

72
5134
by: Stephen Poley | last post by:
I have quite often (as have probably many of you) come across HTML forms with irritating bits of Javascript attached. The last straw on this particular camel's back was a large form I was asked to...
69
5960
by: Stephen Poley | last post by:
I have quite often (as have probably many of you) come across HTML forms with irritating bits of Javascript attached. The last straw on this particular camel's back was a large form I was asked to...
4
9280
by: Stuart Perryman | last post by:
Hi, I have the following code which works just fine in IE6 but not in Firefox. It is an extract of several table rows each with an individual form. It is generated by php. <form...
6
1894
by: drec | last post by:
I am just learning Javascript and I would like to create a basic form that gives me two options. This will be using either checkbox or radio input type, however I would like the second option to...
2
2619
by: Ralph | last post by:
Hi I don't understand why it's not working: function schedule(imTop){ this.tdImagesTop = imTop; } schedule.prototype.selectEl = function() { alert(this.tdImagesTop);
0
7106
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7181
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5442
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4874
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1381
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
600
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
267
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.