473,385 Members | 2,014 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

attribute name problem

This doesn't work:
<head>
<!-- some things snipped -->
<script>
function display()
{
alert("hey");
}
</script>
</head>
<body>
<form >
<input type="button"
name="display" <!-- Problem -->
value="Display All"
onclick="display()" />
</form>
</body>


But with one character different, this does:

<!-- more things snipped -->
<form >
<input type="button"
name="displa" <!-- Problem solved -->
value="Display All"
onclick="display()" />
</form>
The difference is in the name attribute. I can name it "displa",
"displays", "displat", or "displa*" and it works. But when I call it
"display" it doesn't work.

Why?
Thanks.
Dennis
Jul 23 '05 #1
7 1170
ml***@yahoo.com (Dennis) writes:
function display() <input type="button"
name="display" <!-- Problem -->
The problem is that you are using IE, and IE has decided to make all
named elements available as properties of the global object (i.e., as
global variables).

That means that the global variable "display", which starts out
pointing to the function, is overwritten with a reference to the input
element.
onclick="display()" />
So this fails because "display" is not a function.
But when I call it "display" it doesn't work.


"doesn't work" is about as useless as an error report can be.
My *guess* is that you get an error message (or would get one if you
have error messages enabled, which you should) saying that "display"
is not a function.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #2
On 7 Aug 2004 11:08:58 -0700, Dennis <ml***@yahoo.com> wrote:

[snip]
The difference is in the name attribute. I can name it "displa",
"displays", "displat", or "displa*" and it works. But when I call it
"display" it doesn't work.

Why?


As I'm sure you're aware, most browsers accept the shortcut form/control
accessor that looks like:

document.formName.controlName

In order for this to work, every named form (formName, above) is made a
property of the document object. Likewise, every named form control is
made a property of its parent form.

When the intrinsic event for a form control is executed, the form object
itself is added, for reasons unknown to me, to the scope chain. This scope
chain is used to resolve identifiers. As I already mentioned, named form
controls are added to the form object as properties, so if you use a
control name as an identifier, it will be found in the form. This is why
renaming the form control (or the function) produces the more desired
results: the name you're looking for can't be found in the form object, so
the browser looks to the global object and finds it there[1].

It should be noted that this only occurs when the form control is
contained within a form. If it's by itself, only the control itself, and
the global object, are part of the scope chain[2].

Mike

[1] Apologies for any discrepancies in that description - my knowledge of
the scope chain is a little fuzzy, particularly as to why the form is
added.
[2] Well, that's what I've seen anyway.

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail
Jul 23 '05 #3
On Sat, 07 Aug 2004 20:42:40 +0200, Lasse Reichstein Nielsen
<lr*@hotpop.com> wrote:
ml***@yahoo.com (Dennis) writes:
function display()

<input type="button"
name="display" <!-- Problem -->


The problem is that you are using IE, and IE has decided to make all
named elements available as properties of the global object (i.e., as
global variables).


I thought that at first, but Opera and Mozilla also display the same
behaviour. See my other post for my explanation. Am I correct?

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail
Jul 23 '05 #4
Michael Winter wrote:
<snip>
It should be noted that this only occurs when the form
control is contained within a form. If it's by itself,
only the control itself, and the global object, are
part of the scope chain[2].

<snip>

The exact scope chain created by various browsers varies enormously
(including some that do not modify the normal JS scope chain with only
the global object on it), and can depend on the context in which the
element appears. Mozilla has a strong tendency to add all ancestors in
the DOM tree to the scope chin of elements outside of forms.

Google for an exchange between Dom Leonard and me with the subject
"Works in ie and opera not mozilla" for code to examine the scope chain
in various browsers.

Richard.
Jul 23 '05 #5
"Michael Winter" <M.******@blueyonder.co.invalid> writes:
When the intrinsic event for a form control is executed, the form
object itself is added, for reasons unknown to me, to the scope
chain.
I believe this convenience feature was added in the early Netscape
versions.
It should be noted that this only occurs when the form control is
contained within a form. If it's by itself, only the control itself,
and the global object, are part of the scope chain[2].


And the document element. It's only the form element that is missing.

Which elements is added to the scope chain depends on the browser. At
least Opera 5+ and Netscape 2 omit the document element from the scope
chain. Opera 4 has no special scope chain at all, so only the global
object is visible. Other browsers (Netscape 3+, Mozilla FF, IE 4+)
has a scope chain consisting of the global object, document, the form
and the form control. For all but NS4, an input element outside a form
still has the document object and itself in the scope chain (NS4 can't
understand input elements outside of a form).

I haven't checked, e.g., Macintosh browers.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #6
>"doesn't work" is about as useless
as an error report can be.


Yes. It sure is. Please forgive my carelessness.

"doesn't work" means that the page loads just fine, but when I hit the
*display* button I get the message "Object doesn't support this
property or method," and the function is never called. The function,
defined elsewhere on the page, is supposed to display an array of
records the user has entered. According to the tutorial I'm using the
error message doesn't make sense (to me) because I'm using standard
properties.

Dennis
Jul 23 '05 #7
>As I'm sure you're aware, . .

Actually, this is my first attempt with Javascript, and my second
attempt with html. I'm definitely a newbie.

Thanks for the explanation.

Dennis
Jul 23 '05 #8

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

Similar topics

0
by: Carl | last post by:
I want to create a generic xslt that would take xml input like: ########################################################################## <?xml version="1.0" encoding="utf-8" ?>...
4
by: Lénaïc Huard | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello, I've some namespace problems when defining default values for attributes. My problem seems to come from the fact that the attributes are...
12
by: Sammy | last post by:
Hi, my mind is going crazy. I have tried everything I can think of to no avail. I have tried Disable Output Escaping. I tried to think of a way of enclosing the attribute data in a CDATA...
4
by: smita | last post by:
Hi, I have an xml file as below <root> <table id =1> <user>abc</user> <age>25</age> </table> <table id = 2> <user>xyz</user>
1
by: AP | last post by:
Hi, I'm getting the following error trying to validate an xml document against a schema: The 'xsi:noNameSpaceSchemaLocation' attribute is not declared My xml file looks like this: <?xml...
2
by: Ian Griffiths | last post by:
I have been given a schema, instances of which I'm required to be able to consume and generate. I'd like to be able to manipulate these instances as DataSets internally in my application. The...
5
by: emma_middlebrook | last post by:
Hi I've found the rules that cover what is a valid attribute name here: http://www.w3.org/TR/2006/REC-xml-20060816/ 2.3 Common Syntactic Constructs Is there anything already in the dotnet...
1
by: Tedros.G | last post by:
Hi I have an attribute the appears in both the root node and child node for example, below the attribute VERSION appears in the rood node (PRODMSG ) and a child node (OPERATION ) ================...
6
by: Adam Donahue | last post by:
As an exercise I'm attempting to write a metaclass that causes an exception to be thrown whenever a user tries to access 'attributes' (in the traditional sense) via a direct reference. Consider:...
0
by: pradip sonar | last post by:
Hello, I am having a problem with Xalan transforming a document containing Japanese characters. (An initial note: the problem does not occur on my Windows development machine, only on the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.