View Full Version : Validating Strict xhtml / Javascript


Ayla
09-25-2009, 10:08 PM
Hello,

First, I'm glad this forum has re-opened because I found you all to be so helpful in the past.

Second, my dilemma. I am learning Javascript. I know this may not be the place to put this or if you all even help with advanced stuff like this any more, but it does pertain to strict xhtml and w3c validation. I was told by a teacher that I should keep the name attribute in my Javascript tags, along with an id of the same name, because older browsers don't read the id tag in Javascript and they may need the name tag. So I have a Javascript drop-down-menu in my website that has both an id and a name attribute within it. The problem is that I need to validate this site as strict xhtml and the w3c validator sees the name tag and thinks I'm trying to do stuff with targets (which it obviously does not allow). Does anyone have any advice on how to get around this? I've been Googling it, but I can't seem to find anything I understand that doesn't suggest pulling the name attributes out completely.

Thanks in advance,
Ayla

disconnect277
09-25-2009, 11:02 PM
I don't think I've ever seen "name" in a script tag...

But I not a JS expert....

I've only seen

<script type="text/javascript" language="JavaScript"></script>

(And just simple script tags)

Not sure if this is what you mean by "tags"

Ayla
09-26-2009, 06:22 PM
Oh, you're right. I think I described it wrong. The javascript is linked to this section of inline code within the body tags, which contains both the name and id for the Javascript to reference. My understanding of the Javascript was that older browsers will intrepret getElementById(id) as getElementById(name). Maybe I'm wrong. I'm a little slow on the programming uptake.

Menu Code:

<ul id="menu">
<li><a href="index.htm">Home</a></li>
<li><a href="#" onmouseover="menuopen('moreflowers')">All Perennials</a>
<div id="moreflowers" name="moreflowers">
<a href="fullsun.htm">Full Sun</a>
<a href="fullshade.htm">Full Shade</a>
</div>
</li>
</ul>


Javascript linking to it:

var sublayer = 0;

// open hidden layer
function menuopen(id)
{
// close old layer
if(sublayer) sublayer.style.visibility = 'hidden';

// get new layer and show it
sublayer = document.getElementById(id);
sublayer.style.visibility = 'visible';

}
// close showed layer
function menuclose()
{
if(sublayer) sublayer.style.visibility = 'hidden';
}

document.onclick = menuclose;

disconnect277
09-26-2009, 07:28 PM
Ah, ok. :)

The only time I've seen the name used, is with forms. Otherwise I always used Id.