Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Making a canned script validate in XHTML Strict

    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/dynamici...nylinkcss2.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/dynamici...inkvertical.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:
    Code:
    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!
    Last edited by kvandekrol; 02-07-2007 at 06:21 AM.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    holy crap, that never occurred to me. With all the talk demonizing javascript events inside links lately, 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?

  • #4
    Regular Coder
    Join Date
    Jan 2007
    Posts
    213
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Matthew Bagley
    Paramiliar Design Studios
    Website Design | Website Development | Search Engine Optimisation (SEO)

  • #5
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Quote Originally Posted by neomaximus2k View Post
    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.

  • #6
    Regular Coder
    Join Date
    Jan 2007
    Posts
    213
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Matthew Bagley
    Paramiliar Design Studios
    Website Design | Website Development | Search Engine Optimisation (SEO)

  • #7
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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/dynamici...inkvertical.js) so that the dropdown menu appears at the left side of the link instead of the right side. How do I do that?

  • #8
    Regular Coder
    Join Date
    Jan 2007
    Posts
    213
    Thanks
    0
    Thanked 0 Times in 0 Posts
    invalid link says it cant find the file.
    Matthew Bagley
    Paramiliar Design Studios
    Website Design | Website Development | Search Engine Optimisation (SEO)

  • #9
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by neomaximus2k View Post
    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.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •