Script Attribute Type


 

The Script Attribute Type is a data type defined by XHTML Modularisation 1.1, declared in the DTD as XML 1.0 type CDATA.
Reference: *W3C - XHTML Modularisation 1.1 - Attribute Types

Specific Attributes with Type Script

  1. onblur:
    This is declared on the elements: a, area, label, input, textarea, select, button
  2. onchange:
    This is declared on the elements: input type="text", input type="password", input type="file", input type="checkbox", input type="radio", textarea, select
  3. onfocus:
    This is declared on the elements: a, area, label, input, textarea, select, button
  4. onload:
    This is declared on the element: body
  5. onreset:
    This is declared on the element: form
  6. onselect:
    This is declared on the elements: input type="text", input type="password", input type="file", textarea
  7. onsubmit:
    This is declared on the element: form
  8. onunload:
    This is declared on the element: body

Common Attributes with Type Script

From the Events Attribute Collection:
  1. onclick
  2. ondblclick
  3. onmousedown
  4. onmouseup
  5. onmouseover
  6. onmousemove
  7. onmouseout
  8. onkeypress
  9. onkeydown
  10. onkeyup

Attribute Value for Type Script

A script expression to be passed to the appropriate scripting engine

If you use any attributes of Type Script, the MIME type of the scripting language used should always be provided in a Content-Script-Type HTTP header.

It is good practice not to use these attributes, however, and instead to include external scripts (via script elements) which add any handlers unobtrusively. This makes code more self-contained and also the XHTML is easier to maintain if it doesn't contain any events attributes.

Handling Invalid Characters

Within XHTML 1.1 attribute values:
  • Every less-than character (<) within an attribute value must be escaped as &lt; (or &#60;).
  • Every ampersand character (&) which does not denote the start of an entity or character reference (e.g. &lt;) must be escaped as &amp; (or &#38;).
  • Every double quote character (") must be escaped as &quot; (or &#34;) if using double quotes to delimit the attribute value
  • Every single quote character (') must be escaped as &#39; if using single quotes to delimit the attribute value (alternatively &apos; may be used if compatibility with HTML isn't necessary - see Character Entities Predefined by XML 1.0)

For example, the invalid ampersand characters in the following script attribute have been escaped as &amp;

<body onload="if ( myobj &amp;&amp; myobj.setup ) myobj.setup();">

Each of the &amp; entity references in the above example will be replaced by an ampersand character by the XML Processor during *Attribute-Value Normalisation. The upshot of this is that the scripting engine will not see the entity references but instead the intended onload code:

if ( myobj && myobj.setup ) myobj.setup();

Page Footer & Copyright

Copyright © Sally Maughan 2005-2009 (Page last updated on 01 Oct 2009)

*Valid XHTML 1.1 - hosted by *Openstrike

Content based on the W3C Working Draft: *XHTML 1.1 and Recommendation: *XHTML Modularisation 1.1.

W3C, XHTML, XML, HTML, CSS and MathML are *Trademarks of the W3C (*MIT, *ERCIM, *Keio) with which the site's author has no connection.


Up, Next & Previous Links

Your Location

Home > XHTML 1.1 Home > Data Types in XHTML 1.1 > Attribute Types (XHTML 1.1) > Script Attribute Type