...

View Full Version : ordered list invalid markup when adding value=""



snarf1974
05-15-2009, 01:14 PM
Hi,

Not sure if there is a simple workaround for this.

I've got an ordered list, but somewhere in the list I want to skip a number, like so:



<ol>
<li>blah</li>
<li>blah</li>
<li>blah</li>
<li value="5">blah</li>
<li>blah</li>
</ol>


It looked like this was fine, but it came back as invalid XHTML 1.0 Strict!
Is there anyway to negate this error?

Many Thanks

:)

SB65
05-15-2009, 01:23 PM
Use a transitional doctype instead?

VIPStephan
05-15-2009, 01:31 PM
As you notice the value attribute (and the start attribute) for lists is not valid. It used to be but has been marked as deprecated for HTML 4 and XHTML in favor of CSS counters (https://developer.mozilla.org/En/CSS_Counters).

However, implementation is incomplete, I think. Especially Internet Explorer is gonna be our best friend again. You may be able to manipulate it in a cross-browser way with JavaScript (maybe even as addition to the CSS way to complement for devices that don’t support it) or just don’t care about the failure to validate in this case (even the W3C says that documents don’t necessarily have to be 100% valid as long as they are well formed).

However, the worst thing you could do is change the doctype (for example to “transitional”) just to get a “valid” label. That’s the wrong approach! Strict is the only correct option and I’d stongly ask you to stick to it.

snarf1974
05-15-2009, 01:38 PM
Thanks VIPStephan, I agree that xhtml 1.0 Strict! is definately the best option, and transitional shouldn't be entertained.

I'll probably not go down the javascript route, but thanks for the swift response

Rowsdower!
05-15-2009, 02:18 PM
What about something like this:
<!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>skip number</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
</head>
<body>
<ol>
<li>blah</li>
<li>blah</li>
<li>blah</li>
<li style="visibility:hidden;margin-top:-1.25em;">skipping this number</li>
<li>blah</li>
<li>blah</li>
</ol>
</body>
</html>

This might not be "semantic" enough for some people but it seems like this should work...

SB65
05-15-2009, 02:27 PM
Ok, I realise I'm arguing against a number of people far more experienced than me here, but isn't hiding a field or using javascript adding unnecessary complexity?

And isn't the transitional doctype designed precisely for this sort of occurrence?

I've read all the stuff about strict doctypes encouraging proper markup, separation of style from content and all that, but using a transitional doctype doesn't prevent you from doing this.

Are there any real-world disadvantages to using transtional instead of strict?

Off to get my tin helmet now....
Seriously, I'm not trying to provoke a big row on this one.

Rowsdower!
05-15-2009, 02:32 PM
Ok, I realise I'm arguing against a number of people far more experienced than me here, but isn't hiding a field or using javascript adding unnecessary complexity?

And isn't the transitional doctype designed precisely for this sort of occurrence?

I've read all the stuff about strict doctypes encouraging proper markup, separation of style from content and all that, but using a transitional doctype doesn't prevent you from doing this.

Are there any real-world disadvantages to using transtional instead of strict?

Off to get my tin helmet now....
Seriously, I'm not trying to provoke a big row on this one.

Beats me, I'm just trying to provide a solution within the parameters set by the OP. I aim for strict wherever possible but in a case like this I'd probably consider just downgrading to transitional, but that's me... Different strokes for different folks!

VIPStephan
05-15-2009, 02:59 PM
Ok, I realise I'm arguing against a number of people far more experienced than me here, but isn't hiding a field or using javascript adding unnecessary complexity?

And isn't the transitional doctype designed precisely for this sort of occurrence?

Well, actually no, the transitional doctype wan’t invented to resort back to non-standard code just to get a “valid” document. Its original purpose was to ease the transition from documents coded after old, non-standard methods to a standards compliant markup. It provides a way to apply at least something to old websites that used to have no document type definition at all so the HTML parser knows what actually to parse. For this reason a transitional doctype won’t penalize the use of deprecated elements or attributes. But the actual definition of true valid HTML is the strict definition.

In a nutshell: Newly created websites should always get the strict doctype. The transitional doctype is only for already existing websites that are in the transition of old non-standard code (with no doctype) to standards compliant code.

As to the JavaScript issue: I wasn’t actually thinking of hiding a field with JavaScript but more in the way of changing the counter of the list items through JS or dynamically adding/changing the numbers with JS, skipping one value (where the CSS method wouldn’t apply).

Of course this is a little more complex than using deprecated but working attributes but on the other hand it’s a lot cleaner and more modularized (if you make use of unobtrusive JavaScript (http://onlinetools.org/articles/unobtrusivejavascript/)).

However, at the end of the day it’s totally your choice what you do. You aren’t breaking any laws by writing tag soup.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum