How can I convert this to XHTML 1.1 Strict?
June 6, 2004 4:12 PM Subscribe
I have this HTML:
Response by poster: Aww, shite. Worked on preview.
Trying again. I have this HTML:
<select name="topic" onChange="submit(this)">
How can I convert this to XHTML 1.1 Strict? There's no onChange attribute, so it seems like I'd have to do everything in a <script> in the <head>, but I'm at a loss as to how.
posted by reklaw at 4:14 PM on June 6, 2004
Trying again. I have this HTML:
<select name="topic" onChange="submit(this)">
How can I convert this to XHTML 1.1 Strict? There's no onChange attribute, so it seems like I'd have to do everything in a <script> in the <head>, but I'm at a loss as to how.
posted by reklaw at 4:14 PM on June 6, 2004
There is no XHTML 1.1 Strict. XHTML 1.1 is similar to XHTML 1.0 Strict, though. The following is valid in XHTML 1.0 Strict:
<!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>Test Page</title>
</head>
<body>
<div>
<select name="test" onchange="submit(this)">
<option value="test1">test1</option>
<option value="test2">test2</option>
</select>
</div>
</body>
</html>
Notice I used onchange, not onChange. XHTML tags should be 100% lower-case.
posted by tomorama at 4:33 PM on June 6, 2004
<!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>Test Page</title>
</head>
<body>
<div>
<select name="test" onchange="submit(this)">
<option value="test1">test1</option>
<option value="test2">test2</option>
</select>
</div>
</body>
</html>
Notice I used onchange, not onChange. XHTML tags should be 100% lower-case.
posted by tomorama at 4:33 PM on June 6, 2004
Presumably you're trying to submit a form (as you can't really submit a select box). If so, bear in mind that the name="" attribute is no longer used in XHTML 1.1. The following code validates...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Test Page</title>
</head>
<body>
<form id="myform" action="processform.php" method="post">
<div>
<select name="test" onchange="javascript: submit(this);">
<option value="test1">test1</option>
<option value="test2">test2</option>
</select>
</div>
</form>
</body>
</html>
posted by filmgoerjuan at 4:57 PM on June 6, 2004
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Test Page</title>
</head>
<body>
<form id="myform" action="processform.php" method="post">
<div>
<select name="test" onchange="javascript: submit(this);">
<option value="test1">test1</option>
<option value="test2">test2</option>
</select>
</div>
</form>
</body>
</html>
posted by filmgoerjuan at 4:57 PM on June 6, 2004
Response by poster: Ah... yeah, there is no XHTML 1.1 Strict, you're right. I just meant XHTML 1.1. I feel especially boneheaded after screwing up this ask mefi post and you both showing me that all I really needed to do was change "onChange" to "onchange".
Of course, if the damn validator had just said 'capital letter! invalid!' instead of 'there is no attribute "onChange', it could have spared me all this. Follow up question: is there an XHTML 1.1 validator that produces more helpful errors than the w3c's one?
posted by reklaw at 5:15 PM on June 6, 2004
Of course, if the damn validator had just said 'capital letter! invalid!' instead of 'there is no attribute "onChange', it could have spared me all this. Follow up question: is there an XHTML 1.1 validator that produces more helpful errors than the w3c's one?
posted by reklaw at 5:15 PM on June 6, 2004
Nothing wrong with the above answers. But should you want to put your event handler in the <head>, you could do this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>OnChange for XHTML</title>
<script type="text/javascript">
window.onload = addEvent;
function addEvent()
{
document.getElementById("theSelector").onchange = doSomething;
}
function doSomething()
{
// your event code here
}
</script>
<head>
<body>
<form id="theForm">
<select id="theSelector">
<option>Item 1</option>
<option>Item 2</option>
<option>Item 3</option>
<option>Item 4</option>
<option>Item 5</option>
<option>Item 6</option>
</select>
</form>
</body>
</html>
posted by normy at 5:50 PM on June 6, 2004
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>OnChange for XHTML</title>
<script type="text/javascript">
window.onload = addEvent;
function addEvent()
{
document.getElementById("theSelector").onchange = doSomething;
}
function doSomething()
{
// your event code here
}
</script>
<head>
<body>
<form id="theForm">
<select id="theSelector">
<option>Item 1</option>
<option>Item 2</option>
<option>Item 3</option>
<option>Item 4</option>
<option>Item 5</option>
<option>Item 6</option>
</select>
</form>
</body>
</html>
posted by normy at 5:50 PM on June 6, 2004
Response by poster: Thanks for that, too -- I bet that'll come in handy someday.
posted by reklaw at 6:47 PM on June 6, 2004
posted by reklaw at 6:47 PM on June 6, 2004
Of course, if the damn validator had just said 'capital letter! invalid!' instead of 'there is no attribute "onChange'
But there is no attribute onChange. The validator it only knows what attributes are defined in the document type definition. It can't tell that all the legal attributes are lower-case any more than it can tell whether they are all varieties of cheese.
posted by kindall at 6:53 PM on June 6, 2004
But there is no attribute onChange. The validator it only knows what attributes are defined in the document type definition. It can't tell that all the legal attributes are lower-case any more than it can tell whether they are all varieties of cheese.
posted by kindall at 6:53 PM on June 6, 2004
Response by poster: But since all-lowercase tags are a requirement for valid XHTML, surely it should warn when they aren't, instead of giving cryptic clues?
posted by reklaw at 7:57 PM on June 6, 2004
posted by reklaw at 7:57 PM on June 6, 2004
So send them feedback. Use the link to the right of the error message to comment on it.
posted by DrJohnEvans at 9:26 AM on June 7, 2004
posted by DrJohnEvans at 9:26 AM on June 7, 2004
But since all-lowercase tags are a requirement for valid XHTML, surely it should warn when they aren't, instead of giving cryptic clues?
The validator, I'm sure, doesn't know it's validating XHTML. It's almost certainly an XML validator working from the XHTML DTD. That's the whole point of making HTML into valid XML, after all -- so you can use XML tools on it. The "lowercase only" bit is a requirement of XHTML, not XML, so you can't expect a validator to know about it. As I said, the validator only knows what the valid tags and attributes are, it has no way to recognize that they all follow a pattern such as "all lowercase" or "all uppercase."
posted by kindall at 11:01 AM on June 7, 2004
The validator, I'm sure, doesn't know it's validating XHTML. It's almost certainly an XML validator working from the XHTML DTD. That's the whole point of making HTML into valid XML, after all -- so you can use XML tools on it. The "lowercase only" bit is a requirement of XHTML, not XML, so you can't expect a validator to know about it. As I said, the validator only knows what the valid tags and attributes are, it has no way to recognize that they all follow a pattern such as "all lowercase" or "all uppercase."
posted by kindall at 11:01 AM on June 7, 2004
This thread is closed to new comments.
posted by Keyser Soze at 4:14 PM on June 6, 2004