HighDots Forums  

Re: Object doesnt support this function or property?????

Javascript JavaScript language (comp.lang.javascript)


Discuss Re: Object doesnt support this function or property????? in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Richard Cornford
 
Posts: n/a

Default Re: Object doesnt support this function or property????? - 07-02-2003 , 05:24 PM






"Draken" <lord_draken_korin (AT) hotmail (DOT) com> wrote

<snip>
Quote:
My problem is though that it tells me I can not use
onClick="menu();" IE gives me the error "Object does not support
this function or property"
You are suffering from a scope resolution problem.

Quote:
Heres what I have so far.
In the head section:
function menu() {
for (i=0;i<=2;i++) {
if (document.menuform.menu[i].checked=="1") {
parent.main.location.href="document.menuform.menu[i].value + '.html'"
}
}
}
This function definition creates a global variable (property of the
global object) with the name "menu".

Quote:
in the body:
INPUT TYPE="RADIO" NAME="menu" VALUE="news" onClick="menu();"
This creates a property of the form object that has the name "menu" and
represents the collection of radio buttons that have the name "menu".

Quote:
A HREF="javascript: menu()"
onMouseOver="document.menuform.menu[0].checked='1'">News
/A><BR
Modern browsers resolve an identifier used in event handling code
("menu" in this case) by checking to see if the - this - object (the
radio button to which the event handler is attached) contains a property
with that name. If the property is not found all of the objects in the
DOM tree between the radio button object are searched in turn (moving
towards the DOM root at the global object) to see if any of them have a
property by that name. This process ends at the global object where the
"menu" function may be found. However, one of the ancestors of the radio
button object is the form element, and the form element does have a
property named "menu" (the collection of radio buttons named "menu") so
the JavaScript interpreter returns a reference to that object as its
response to the use of "menu" as an identifier. The attempt to execute
the radio button collection involves a call to an internal - [[call]] -
method of the object and collection objects, not being function objects,
do not have a - [[call]] - method. Hence - object does not support this
property of method. (error reports in Mozilla/Netscape 7 or Opera 7 are
much more informative than in IE.)

javascript: pseudo-protocol code is executed in the global context so
its scope resolution only involves the global object. A "menu"
identifier will always be resolved as the global "menu" function.
However, the javascript pseudo-protocol should not be used in this way
as it causes many unexpected problems. See:-

<URL: http://jibbering.com/faq/#FAQ4_24 >

The solution is to avoid the naming conflict by re-naming either the
radio buttons or the global function. (though any uses of the javascript
pseudo-protocol should also be changed to properly formed onClick code.)

Quote:
The anchor works fine, moving your mouse over it makes the radio
checked and goes to the page, clicking on the radio button itself
causes this error.

Two side notes... to make the loop dynamic is there a way to obtain the
amount of items in the array of document.menuform.menu ??
snip

document.menuform.menu.length

Richard.
--

Example JavaScript DOM listings for: Opera 7.11,
Mozilla 1.2 and ICEbrowser 5.4
<URL: http://www.litotes.demon.co.uk/dom_root.html >




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.