Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   strange behaviour of getElementsByName and method name in IE and FF (http://www.velocityreviews.com/forums/t939901-strange-behaviour-of-getelementsbyname-and-method-name-in-ie-and-ff.html)

Thomas 'PointedEars' Lahn 11-19-2009 01:09 PM

Re: strange behaviour of getElementsByName and method name in IE and FF
 
..rhavin grobert wrote:

> the following little test-markup doesnt work...
> in firefox, i dont even get the names of the elements,
> in IE, i get the names but the getElementsByName() returns an emty
> array.
> [...]
> <li id="m1" name="menu" ><a href="#" onClick="ps_page('m1',
> 'p1');">Daten</a></li>
> <li id="m2" name="menu" ><a href="#" onClick="ps_page('m2',
> 'p2');">Musik</a></li>
> </ul></div>
> <div id="p1" name="page" >
> <p>div 1</p>
> </div>
> <div id="p2" name="page" >
> <p>div 2</p>
> </div>


Neither LI elements nor DIV elements have a `name' attribute.

<http://validator.w3.org/>


PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8300dec7@news.demon.co.uk>

Thomas 'PointedEars' Lahn 11-19-2009 02:21 PM

Re: strange behaviour of getElementsByName and method name in IE and FF
 
..rhavin grobert wrote:

> Thomas 'PointedEars' Lahn wrote:
>> Neither LI elements nor DIV elements have a `name' attribute.

>
> Ok, thx for your answer; i cant even imagine what stupidity let the
> w3c choose to deprecate 'name' -


Blaming others for your mistakes is not going to get you any more good
answers here.

The W3C did not deprecate the `name' attribute for those elements; it was
never part of the markup language to begin with. If you read the HTML 4.01
Specification as I already recommended, you can see which elements have a
`name' attribute and which do not (there is an "attributes" overview linked
at the top).

> do you perhaps have another suggestion for naming a couple of divs?


Use the `id' attribute.

> i need each div to have an unique id (the id) and a common name...


Let's say you have elements with the following IDs:

id1
id2
id3

Then you can iterate over them as follows:

var o, i = 1;
while ((x = document.getElementById("id" + i)))
{
// ...
i++;
}

It begs the question what do you think this should be good for, though. Your
approach is most likely wrong. Menus should be implemented with nested
lists (UL in LI in UL) so that the menu is based on semantic markup, thereby
meeting accessibility guidelines and legislation. The Web is full of good
CSS examples (those also work without scripting in most browsers) these
days.


PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann

.rhavin grobert 11-19-2009 02:31 PM

strange behaviour of getElementsByName and method name in IE and FF
 
the following little test-markup doesnt work...
in firefox, i dont even get the names of the elements,
in IE, i get the names but the getElementsByName() returns an emty
array.

it would be very nice if someone could have a look at it and tell me,
what the hell is going on here;-(

TIA, ~.rhavin;)
__________________________________________________ _____________

<html><head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<script type="text/javascript" >

function ps_page(menuID, pageID)
{
blur();
alert('ps_page(' + menuID + ', ' + pageID+ ')');

pageelm = document.getElementById(pageID);
menuelm = document.getElementById(menuID);
alert('names(pages): ' + pageelm.name + ', names(menues): ' +
menuelm.name );

pagegrp = document.getElementsByName(pageelm.name);
menugrp = document.getElementsByName(menuelm.name);
alert('size(pages): ' + pagegrp.length + ', size(menues): ' +
menugrp.length );

return true;
}
</script>
</head><body>
<div id="tabmenu"><ul>
<li id="m1" name="menu" ><a href="#" onClick="ps_page('m1',
'p1');">Daten</a></li>
<li id="m2" name="menu" ><a href="#" onClick="ps_page('m2',
'p2');">Musik</a></li>
</ul></div>
<div id="p1" name="page" >
<p>div 1</p>
</div>
<div id="p2" name="page" >
<p>div 2</p>
</div>
<p>test</p>
</body><html>

.rhavin grobert 11-19-2009 03:05 PM

Re: strange behaviour of getElementsByName and method name in IE andFF
 
On 19 Nov., 14:09, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
> Neither LI elements nor DIV elements have a `name' attribute.


Ok, thx for your answer; i cant even imagine what stupidity let the
w3c choose to deprecate 'name' - do you perhaps have another
suggestion for naming a couple of divs? i need each div to have an
unique id (the id) and a common name...


All times are GMT. The time now is 07:05 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57