
Originally Posted by
jonnycash
As i mentioned earlier I've not been writing code long so I'm lost when you say my mark up is invalid.
As I'm sure you can appreciate, as a language, HTML has various rules on what's allowed and not allowed. Some of these rules are inherent to the language itself, whilst others vary based on the document type (Strict, Transitional, or Frameset). A document is valid when it obeys these all of these syntax rules.
Most of these rules are intuitive, like making sure tags don't overlap:
HTML Code:
<strong><a href="/somewhere">Link text</strong></a> <!-- Wrong! -->
<strong><a href="/somewhere">Link text</a></strong> <!-- Right -->
attributes don't appear twice within the same start-tag, and the value of each id attribute is unique within a document.
The others - those that vary based on document type - are sensible, but require a familiarity with the various elements in HTML. What these rules basically boil down to is:
- Which start- and end-tags are optional, required, or forbidden
- Which attributes (if any) are required for a given element
- What content is allowed within a given element
For example, both start- and end-tags are required for anchors (a elements).
HTML Code:
<a ...>Anchor text</a>
With paragraphs (p elements), the end-tag is optional, so:
is legal (but it's good form to always include optional end-tags). With input elements, the end-tag is forbidden; only the start-tag is used to include the element.
Examples of required attributes include the type attribute for script and style elements, and the action attribute for form elements.
Permitted content gets a little trickier to summarise, particularly because there are many elements that have their own restrictions.
First of all, it's convenient to categorise elements into two groups: in-line elements, and block-level elements. Block-level elements are typically used as containers or to group elements. Examples include tables, paragraphs, lists, headings, and divisions (div elements). Some block-level elements (like divisions, forms, lists and tables) can contain other block-level elements, whilst others (such as paragraphs and headings) can only contain in-line elements. In-line elements are typically related to text, or that sort of content. They include anchors (a elements), images (img elements), phrase elements (strong, em, code, dfn), and form controls (input, select, textarea).
The limitations of element content again follow the pattern of optional, required, and forbidden. For example, the table element itself cannot directly contain anything other than table-related elements, namely captions, columns and column groups (col and colgroup, respectively), table sections (tbody, thead, and tfoot) and table rows (tr elements). Similarly, table rows can only contain table cells and table headers (td and th, respectively). As another example, though anchors can contain in-line elements, that cannot include other anchors.
The HTML Specification lists all of the elements, and discusses all of these rules, but it's a lot to read (though it's something that should be read). It also uses SGML to describe elements, attributes, and their contents, so the SGML primer in chapter 3 is a "must read".
I'm using dreamweaver and if I go to 'validate markup' I get loads of errors, even though my browsers display the pages no problem.
Browsers have been engineered over time to try and make sense of errors. If a browser simply gave up upon encountering an invalid construct (something that's perfectly acceptable, by the way), most of the Web would be unusable with that browser. However, error correction mechanisms vary from browser-to-browser, with each sometimes making subtly different alterations. As such, it's not a good idea to rely on that feature. Moreover, I would hope a little personal pride would drive people into authoring well-written documents.
I don't know what exactly is wrong with the table elements?
In some cases, you have table cells as children of the table element itself:
HTML Code:
<table>
<td>...</td>
and in others, you have table rows without table cells:
HTML Code:
<table>
<tr>
<div id="projections">
Both of these are forbidden.
Also, I don't understand what you mean by the "inclusion of the html start-tag and script start- and end-tags within a script element."
In the first script element, you've included a html element start-tag:
HTML Code:
<script language="JavaScript"><html>
That is wrong. Later on, you also include the start- and end-tags for a script element, but within a script element. That is, something that would look like:
HTML Code:
<script ...>
<script ...>
</script>
</script>
if there was no intervening text. Again, that is wrong.
Whilst we're here: you should use the type attribute instead of the language attribute.
HTML Code:
<script type="text/javascript">
The former has been deprecated for over nine years. You should also not used markup comments (<!-- ... -->) within either script or style elements.
I've written all my code by hand - I take it this is where I've messed up the table tags?
One doesn't necessarily follow from the other: I write markup by hand. However, you might help yourself spot mistakes by indenting tags, and for elements with end-tags, you might want to write them in pairs. For instance:
HTML Code:
<table>
</table>
HTML Code:
<table>
<tr>
</tr>
</table>
HTML Code:
<table>
<tr>
<td></td>
</tr>
</table>
and so on.
Dreamweaver told me to include the html tag after the <script language="JavaScript"> tag
I must say that even though I dislike Dreamweaver on principle (it's WYSIWYG, which is generally inappropriate for the Web), I find that statement a little hard to believe. Whilst it can produce abysmal markup, even Frontpage (one of the worst authoring programs) isn't that bad.
Seein as I'm constantly adding new elements to the webpage, where do I put this [script] tag you made?
Anywhere after the end-tag for the div element with the id "projections":
HTML Code:
<div id="projections">
<!-- Projected smoking expenses, etc. -->
</div>
<!-- The script element can be inserted at any valid location after this point. -->
<SCRIPT type=text/javascript>
As a rule, quote all attribute values. Though it isn't strictly necessary in some cases (but it is required, here), it'll be easier for the moment than learning when you're allowed to omit them.
Does the code require a lot of work to be corrected please?
Yes. If it didn't, I'd have done you the favour of rewriting it, pointing out the individual problems.
Mike
Bookmarks