By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,712 Members | 2,111 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,712 IT Pros & Developers. It's quick & easy.

Javascript property listener

P: n/a
Hi All,

I am writing a Javascript UI component. I have already written a
"disable()" method for it, but I would like to go one step further in
order to make my component as compatible with existing HTML controls as
possible.

With standard HTML controls we can do this:
myTextField.disabled = true;
and as soon as this property is set, I assume there is a property
listener of some kind that is invoked to change the appearance and
value etc of the control.

I want to write my own 'property listener' to do this with my control.
Can I do it in Javascript or is this too "low level", requiring code at
the browser implementation level?

Rob
:)

Oct 8 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a


Robert Mark Bram wrote:

I want to write my own 'property listener' to do this with my control.
Can I do it in Javascript or is this too "low level", requiring code at
the browser implementation level?


Mozilla's JavaScript engine Spidermonkey allows you to set up setter and
getter functions for individual properties, here is an example:

var object = {
name: 'Kibo',
mDisabled: false
};
object.__defineSetter__(
'disabled',
function (value) {
// could execute any code here
return this.mDisabled = value;
}
);
object.__defineGetter__(
'disabled',
function () {
return this.mDisabled;
}
);

alert(object.disabled);
object.disabled = true;
alert(object.disabled);
But that is not standardized in ECMAScript edition 3, the current
standard the engines implement, and therefore for instance the JScript
engine used in IE or the engine used in Opera do not support that.

That is as far as engines go, in the browser there are some other
possibilities:

If you want to build GUI components in IE then you could look into HTCs
(HTML Components)
<http://msdn.microsoft.com/library/default.asp?url=/workshop/components/htc/reference/htcref.asp>
you can encapsulate your control there and also define properties:
<http://msdn.microsoft.com/library/default.asp?url=/workshop/components/htc/reference/elements/property.asp>

To build GUI components in Mozilla you can use XBL (XML binding language):
<http://developer.mozilla.org/en/docs/XBL>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 8 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.