...

View Full Version : Making a canned script validate in XHTML Strict



kvandekrol
02-07-2007, 05:18 AM
Let me start by saying I'm not very good with JavaScript. I know what it needs to be used for, and I know how to implement it, but sometimes I run across some problems modifying it.

That said, this should be pretty easy for someone to help me out with.. I have a canned script from Dynamic Drive, but it uses Javascript inside the anchor tag (onClick and onMouseover), which doesn't validate in XHTML 1.0 Strict.

The script is here:
http://www.dynamicdrive.com/dynamicindex1/anylinkcss2.htm

I'm sure it's a really simple fix. Basically I just need to move the two elements from the anchor tag to the external script so it validates, and then add a class or ID to the XHTML link that the external script grabs. How do I do this? It would be helpful if you could also give me the couple of lines of text that I can paste directly into the external JavaScript file (which is virtually the same as http://www.dynamicdrive.com/dynamicindex1/anylinkvertical.js except for a couple of minor edits).

Also, the script puts the subnav menu to the right of the link, and I need for it to go to the left instead... is this just a matter of changing a variable or two, or is it more complicated than that? I am almost positive that it's just this section of code that needs to be changed, under the 'dropdownmenu' function:

dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+horizontaloffset+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
..but I've messed around with a couple of different variables and haven't been able to get the right results.

thanks in advance for your help!

_Aerospace_Eng_
02-07-2007, 05:20 AM
They do validate but only in their lowercase counter parts. Just make them onclick and onmouseover. Don't make it harder than it has to be.

kvandekrol
02-07-2007, 05:31 AM
holy crap, that never occurred to me. With all the talk demonizing javascript events inside links lately (http://adactio.com/atmedia2005/), I figured it wasn't standards-compliant to include them anymore. Thanks for the easy fix!

Any pointers on getting the menu to the other side of the link, or would I have better luck posting a new message?

neomaximus2k
02-07-2007, 10:03 AM
If I am reading you right you are saying that the script is not validating in W3C's xhtml validator? remember all javascript has to start with the <!-- // and end in // --> otherwise scripts like that will render it as HTML and find errors.

Bill Posters
02-07-2007, 10:07 AM
If I am reading you right you are saying that the script is not validating in W3C's xhtml validator? remember all javascript has to start with the <!-- // and end in // --> otherwise scripts like that will render it as HTML and find errors.

Better yet, bring them in as external .js files.

neomaximus2k
02-07-2007, 10:33 AM
I totall agree on the external JS file, also means that they only download the file once and it remaines cached resulting in faster website browsing.

kvandekrol
02-07-2007, 01:24 PM
The script has been external from day one. I fixed the validation problem by making the inline event handlers lowercase (instead of onClick or onMouseover). Now my only problem is modifying the code (http://www.dynamicdrive.com/dynamicindex1/anylinkvertical.js) so that the dropdown menu appears at the left side of the link instead of the right side. How do I do that?

neomaximus2k
02-07-2007, 01:33 PM
invalid link says it cant find the file.

felgall
02-07-2007, 09:33 PM
If I am reading you right you are saying that the script is not validating in W3C's xhtml validator? remember all javascript has to start with the <!-- // and end in // --> otherwise scripts like that will render it as HTML and find errors.

Those are instructions to XHTML to comment out the script as if it didn't exist at all. Surely that isn't whhat is wanted or why put the script there in the first place. XHTML does treat the content as PCDATA though unless you tell it that it is CDATA so you need to surround inline scripts with:

/* <![CDATA[ */


/* ]]> */


these go in place of the <!-- and //--> that you would use if you want to comment the script out.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum