Re: XHTML Conversion

by Andrew McFarland <aamcf(at)aamcf.co.uk>

 Date:  Wed, 20 Feb 2002 17:56:59 +0000
 To:  "HWG Techniques" <hwg-techniques(at)hwg.org>
 In-Reply-To:  zydhek1
  todo: View Thread, Original
At 00:28 20/02/02 -0800, Kehvan M. Zydhek wrote:
>except for
>one niggly little detail: the NAME attribute in his FORM tags and one IMG
>tag. XHTML claims NAME to be invalid, but his Javascript breaks unless it's
>there. Does anyone have any suggestions about this?

Which browsers does the JavaScript break in?

In my experience, IE and Mozilla are fine about id in place of name, but 
NS4 gets fussed.

I encourage him to use document.getElementById() to access objects, and to 
wrap everything in if statements, like so:

function wibble() {
         if (document.getElementById)
                 { /* do stuff to document.getElementById('foo') here */
         }
}

That way the script will fail gracefully - and because JavaScript can be 
turned off you should never rely on a function executing successfully.


If you are using this sort of thing a lot, you could put the following in 
your HEAD:

<.script type="text/javascript">
var gebi = document.getElementById
<./script>

This makes the wibble function slightly neater:

function wibble() {
         if (gebi){ /* do stuff to document.getElementById('foo') here */}
}

>We've tried replacing
>NAME for ID, but that's not it, as Javascript is still breaking. I'm sure
>the answer has to do with how Javascript references these items as opposed
>to the XHTML code itself, but am not 100% certain of that.

That would be my guess.

<snip/>
>so posting
>the code in it's entirety would not do, either.

Could you put the page onto a temporary URL? Its hard to think of anything 
more helpful without seeing it.

Andrew

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA