Our new Indie Games subforum is now open for business in G&T. Go and check it out, you might land a code for a free game. If you're developing an indie game and want to post about it, follow these directions. If you don't, he'll break your legs! Hahaha! Seriously though.
Our rules have been updated and given their own forum. Go and look at them! They are nice, and there may be new ones that you didn't know about! Hooray for rules! Hooray for The System! Hooray for Conforming!

Javascript vs. XHTML Strict *SOLVED*

japanjapan Registered User regular
I do a bit of web stuff, so I've inevitably ended up tinkering with Javascript. However, I've run into a problem when using "Strict" XHTML. I've put together a little test case, a simple rollover script using the gold and silver thread markers from the forums:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">; <html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en"> <head> <title>Rollover2</title> </head> <body> <script type="text/Javascript"> <!-- Hide Script if(document.images) { buttonsilver = new Image buttongold = new Image buttonsilver.src = "buttonsilver.png" buttongold.src = "buttongold.png" document.write("if test passed") } else { buttonsilver.src="" buttongold.src="" document.button="" document.write("if test failed") { --> </script> <p> <a href="thing.html" onmouseover="document.button.src = buttongold.src" onmouseout="document.button.src = buttonsilver.src"> <img src="buttonsilver.png" width="16" height="16" name="button" alt="button" /> </a> </p> </body> </html> [/CODE] The problem here is that the "name" attribute in the link element isn't valid under XHTML Strict. My research suggest that the equivalent valid element is "id", but if I change that, the rollover stops working, presumably because the browser thinks "document.button.src" doesn't point to anything. Can anyone tell me the correct attribute to use under XHTML Strict? Should I just use Transitional instead?[CODE]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Rollover2</title>
</head>
<body>
<script type="text/Javascript">
<!-- Hide Script
if(document.images) {
buttonsilver = new Image
buttongold = new Image

buttonsilver.src = "buttonsilver.png"
buttongold.src = "buttongold.png"
document.write("if test passed")
}
else {
buttonsilver.src=""
buttongold.src=""
document.button=""
document.write("if test failed")
{
-->
</script>
<p>
<a href="thing.html"
onmouseover="document.button.src = buttongold.src"
onmouseout="document.button.src = buttonsilver.src">
<img src="buttonsilver.png" width="16" height="16" name="button" alt="button" />
</a>
</p>
</body>
</html>
[/CODE]

The problem here is that the "name" attribute in the link element isn't valid under XHTML Strict. My research suggest that the equivalent valid element is "id", but if I change that, the rollover stops working, presumably because the browser thinks "document.button.src" doesn't point to anything.

Can anyone tell me the correct attribute to use under XHTML Strict? Should I just use Transitional instead?

japan on

Posts

  • Jimmy KingJimmy King Registered User regular
    id should do the trick. Assuming you just set the id to button then set it in the js with document.getElementById("button").src="buttonsilver.png" I believe.

    import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.stringreturners.StringStringReturner;
  • japanjapan Registered User regular
    Jimmy King wrote: »
    id should do the trick. Assuming you just set the id to button then set it in the js with document.getElementById("button").src="buttonsilver.png" I believe.

    This. This is what I needed. The stuff I found suggested that "id" was just a drop-in replacement for the "name" attribute.

    Cheers.

  • Jimmy KingJimmy King Registered User regular
    Just about every time I have to write front end stuff (not very often, fortunately, since I'm terrible at it) I try to use it as a drop in for name on my first attempt and then only remember after it doesn't work.

    import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.stringreturners.StringStringReturner;
  • japanjapan Registered User regular
    Any other common "gotchas?" I'd like to try and keep the good habits I've learned by validating absolutely everything as "Strict."

  • Jimmy KingJimmy King Registered User regular
    Not that I know of. I'm primarily a back end guy, though, so most of my front end work is pretty simple.

    import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.stringreturners.StringStringReturner;
  • japanjapan Registered User regular
    Thanks anyway. I really hate the trivial syntax problems that seem to be endemic in Javascript, I can see myself trying to do as much as possible on the back-end.

    Question asked, question answered

Sign In or Register to comment.