473,668 Members | 2,616 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Setting custom properties

I know that I can read/write custom properties of an object by using
the following:

Setting:
document.all['Control'].customProp = "this";
Getting:
document.all['Control'].customProp;

Is there a way I can run code when this custom property is set. Or
perhaps there is a way to create a custom method?

Example:
<span id="MySpan"><in put type="text"></span>

I'd the property:
document.all['MySpan'].enabled = true;
To automatically do this:
document.all['MySpan'].controls[0].disabled = !thevalue;

OR the method
document.all['MySpan'].enable();
To do this:
document.all['MySpan'].disabled = false;
Jul 23 '05 #1
5 2193
On 30 Aug 2004 14:46:48 -0700, Jason Butera <jj******@hotma il.com> wrote:
I know that I can read/write custom properties of an object by using
the following:

Setting:
document.all['Control'].customProp = "this";
Getting:
document.all['Control'].customProp;
If you plan for this code to run on any browser other than IE (and its
compatibles), don't use document.all. See:

<URL:http://www.jibbering.c om/faq/faq_notes/alt_dynwrite.ht ml#getEl>
Is there a way I can run code when this custom property is set.
There are extensions that allow it, but it seems that a lot of browsers
don't allow it. It's safer to use methods.
Or perhaps there is a way to create a custom method?
You can attach a method to an object by assigning a function reference to
a property. This reference can either be a standard function statement:

function myFunction() {
// do stuff
}

obj.myMethod = myFunction;
obj.myMethod();

or a function expression:

obj.myMethod = function() {
// do stuff
};
obj.myMethod();

Note that in both cases, only 'obj' has the myMethod property. If this
were a user-defined object, you could use the prototype property of the
constructor to add the method universally.

function MyObject() {
}
MyObject.protot ype.myMethod = function() {
};

var obj = new MyObject();
obj.myMethod();

However, support for the prototype object on host objects, such as HTML
elements, is not widely available. It might be easier to define a global
function that takes a reference to the host object in question, and any
other arguments, and work that way.
Example:
<span id="MySpan"><in put type="text"></span>

I'd the property:
document.all['MySpan'].enabled = true;
To automatically do this:
document.all['MySpan'].controls[0].disabled = !thevalue;
SPAN elements don't have a controls collection, even in IE.
OR the method
document.all['MySpan'].enable();
To do this:
document.all['MySpan'].disabled = false;


Only IE, as far as I know, supports the disabled property on non-form
elements.

Hope that helps,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
Thanks a lot Michael.

1. My app is internal for IE only so document.all is OK. I'll keep your
tip in mind for my other apps.

2. I don't need to prototype. I just need to set individual objects.

3. You are correct, span does not have a controls collection. I meant to
say "children".

I appreciate your help. I'll get to work on it!

Jason

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #3
Jason Butera wrote:
I know that I can read/write custom properties of an object by using
the following:

Setting:
document.all['Control'].customProp = "this";
Getting:
document.all['Control'].customProp;
You _don't_ know.

1. document.all is a feature of the IE browser component (IE).

2. The MSDN Library specifies document.all to be a method, not
an object. There is an ambiguity in the IE DOM to allow
collections be referenced like methods and vice-versa, but
I recommend to stick to the documentation:

document.all('C ontrol').custom Prop = "this";

3. You don't test for your references prior to access:
<http://www.pointedears .de/scripts/test/whatami>

4. ECMAScript (3) allows host objects be specified in a
way that it is impossible to add properties to them.
Is there a way I can run code when this custom property is set.
You mean a setter, available in JavaScript. But IE
supports JScript and so you cannot do that there.
Or perhaps there is a way to create a custom method?
A method is but a property of type "function" (and sometimes in the IE DOM,
for host objects, of type "object"), so if you can add properties to an
object, you can add methods as well.
Example:
<span id="MySpan"><in put type="text"></span>
What should this achieve?
I'd the property:
document.all['MySpan'].enabled = true;
To automatically do this:
document.all['MySpan'].controls[0].disabled = !thevalue;
Not in JScript. In JavaScript, in a Gecko-based
browser you could do this (quick hack):

var o;
if (document
&& document.getEle mentById
&& (o = document.getEle mentById('MySpa n')))
{
o.enabled setter = function(v)
{
if (typeof this.controls == "undefined" )
{
this.controls = [];
}

if (typeof this.controls[0] == "undefined" )
{
this.controls[0] = {};
}

this.controls[0].disabled = !v;
}
}

<http://devedge.netscap e.com/library/manuals/2000/javascript/1.5/guide/obj.html#101832 5>
OR the method
document.all['MySpan'].enable();
To do this:
document.all['MySpan'].disabled = false;


This is possible with every ECMAScript compliant implementation,
including JScript, provided that the host object (o) exists and
supports adding properties (see above):

// ...
o.enable = function()
{
this.disabled = false;
}
// ...

In an ECMAScript 3 compliant implementation, like JScript 5.6,
one should do

// ...
try
{
document.all('M ySpan'].enable = function()
{
this.disabled = false;
}
}
catch (e)
{
// handle the exception here
}
// ...
HTH

PointedEars
--
God punishes those who survive too extravagantly.
Jul 23 '05 #4
Thomas 'PointedEars' Lahn wrote:
In an ECMAScript 3 compliant implementation, like JScript 5.6,
one should do

// ...
try
{
document.all('M ySpan'].enable = function()
Should be

o.enable = function()
{
this.disabled = false;
}
}
catch (e)
{
// handle the exception here
}
// ...

PointedEars
Jul 23 '05 #5
> 2. The MSDN Library specifies document.all to be a method, not
an object. There is an ambiguity in the IE DOM to allow
collections be referenced like methods and vice-versa, but
I recommend to stick to the documentation:

document.all('C ontrol').custom Prop = "this";


<url: http://msdn.microsoft.com/workshop/a...ctions/all.asp />

"all Collection"
....
"Remarks - The all collection includes..."
....
"Standards Information - There is no public standard that applies to this collection."
The MSDN Library documentation clearly does not specify document.all to be a method. The
MSDN Library documentation may use "method-like" syntax for collections, but collections are
clearly documented to be collections, not methods.
To add further weight to the argument that [] are the correct notation to use for IE
collections:

<url: http://msdn.microsoft.com/workshop/a...s/elements.asp />

indicates the use of FORM.elements(. ..), yet I doubt the person proposing the use of
document.all() would recommend the use of FORM.elements() , despite their advice to "stick to
the documentation". Continue using document.all[] since it is supported now, and will
continue to be supported long into the future.

--
Grant Wagner <gw*****@agrico reunited.com>
comp.lang.javas cript FAQ - http://jibbering.com/faq

Jul 23 '05 #6

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

Similar topics

8
2545
by: JamesBV | last post by:
My PC's Region setting is set to "English (Canada)"... cause I am in Canada (eh?) (: I'm using VB.net, standard edition (v1?) So I wrote my application based on this Region. I've both Short and Long dates being displayed (including a DateTimePicker). BUT... at work, there are some machines which the Region is the ol' default of "English (United States)". Canadian:
1
2059
by: rforman1 | last post by:
I have found many threads with this question asked and ostensibly answered, but none with an example of how exactly to do it. Help! I know that in order to set up the values of command line arguments from within the IDE, I go to Project Properties, Configuration Properties, and then the text box labeled "Command Line Arguments" under the label "Start Options." But what exactly do I put into that text box? What I want to do is set up a...
6
1679
by: Angel | last post by:
I have a button, combo, and custom control that i created. When I click the button i want to set certain display properties of my custom control depending whats in the combo. I set those properties in the Click_Event in the button control. Unfortunately postback is triggered in the click event before I set the display properties of the control. Is there anyway that I can set these properties before the postback is triggered? I'd like to do this...
1
1219
by: Angel | last post by:
I have a button, combo, and custom control that i created. When I click the button i want to set certain display properties of my custom control depending whats in the combo. I set those properties in the Click_Event in the button control. Unfortunately postback is triggered in the click event before I set the display properties of the control. Is there anyway that I can set these properties before the postback is triggered? I'd like to do this...
8
2259
by: David Lozzi | last post by:
Howdy, I have a user control that is a report to display data. On the page the control is inserted in, I have filter options to filter the report. When I try to do something like this, nothing happens. dim filt as string ... build filter string... UserControl.ReportFilter = filt
0
2588
by: Bishop | last post by:
I've figured out how to create a custom TreeNode with custom properties and I can view those properties at runtime, but I'm not sure how to change them after I've added the custom node to the tree. For example: Public Class CustomTreeNode Inherits TreeNode
6
11068
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to how those properties are set. I want to be able to do two other things: a) add User control instances to my page, filling in the place of placeholder controls, and b) programmatically setting custom properties on those dynamically spawned...
5
7223
by: jegec | last post by:
Hi all! Brief subject: I have to develop an ASP-based application, and build also a specific error handling ASP. After that I had set the virtual directory Custom Error 500;100 to new ASP - and now I have no error handling at all. Even if I reset it to Default! Detailed description:
3
2359
by: William Youngman | last post by:
I am on a team that is developing a proposal generation web application and we are using a custom base page (ProGenBase.cs) located in the app_code directory and all of the app's web pages inherit from this custom page. Additionally I have a main menu tab control that is located in a master page and certain tabs are displayed dependant on the users authentication level. I am using boolean properties in the master page to control the visible...
0
8459
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8889
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8790
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7391
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6206
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5677
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4202
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2017
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.