- From: Ian Hickson via cvs-syncmail <cvsmail@w3.org>
- Date: Thu, 10 Sep 2009 09:53:32 +0000
- To: public-html-commits@w3.org
Update of /sources/public/html5/spec In directory hutz:/tmp/cvs-serv8791 Modified Files: Overview.html Log Message: <script> example. (whatwg r3791) Index: Overview.html =================================================================== RCS file: /sources/public/html5/spec/Overview.html,v retrieving revision 1.2960 retrieving revision 1.2961 diff -u -d -r1.2960 -r1.2961 --- Overview.html 10 Sep 2009 09:35:07 -0000 1.2960 +++ Overview.html 10 Sep 2009 09:53:29 -0000 1.2961 @@ -10941,7 +10941,47 @@ </div><p class="note">When inserted using the <code title="dom-document-write"><a href="#dom-document-write">document.write()</a></code> method, <code><a href="#script">script</a></code> elements execute (typically synchronously), but when inserted using <code title="dom-innerHTML"><a href="#dom-innerhtml">innerHTML</a></code> and <code title="dom-outerHTML"><a href="#dom-outerhtml">outerHTML</a></code> attributes, they do not - execute at all.<h5 id="scriptingLanguages"><span class="secno">4.3.1.1 </span>Scripting languages</h5><div class="impl"> + execute at all.<div class="example"> + + <p>The following sample shows how a script element can be used to + define a function that is then used by other parts of the + document. It also shows how a <code><a href="#script">script</a></code> element can be + used to invoke script while the document is being parsed, in this + case to initialize the form's output.</p> + + <pre><script> + function calculate(form) { + var price = 52000; + if (form.elements.brakes.checked) + price += 1000; + if (form.elements.radio.checked) + price += 2500; + if (form.elements.turbo.checked) + price += 5000; + if (form.elements.sticker.checked) + price += 250; + form.elements.result.value = price; + } +</script> +<form name="pricecalc" onsubmit="return false"> + <fieldset> + <legend>Work out the price of your car</legend> + <p>Base cost: £52000.</p> + <p>Select additional options:</p> + <ul> + <li><label><input type=checkbox name=brakes> Ceramic brakes (£1000)</label></li> + <li><label><input type=checkbox name=radio> Satellite radio (£2500)</label></li> + <li><label><input type=checkbox name=turbo> Turbo charger (£5000)</label></li> + <li><label><input type=checkbox name=sticker> "XZ" sticker (£250)</label></li> + </ul> + <p>Total: £<output name=result onformchange="calculate(form)"></output></p> + </fieldset> + <script> + document.forms.pricecalc.dispatchFormChange(); + </script> +</form></pre> + + </div><h5 id="scriptingLanguages"><span class="secno">4.3.1.1 </span>Scripting languages</h5><div class="impl"> <p>A user agent is said to <dfn id="support-the-scripting-language">support the scripting language</dfn> if <var><a href="#the-script-block-s-type">the script block's type</a></var> matches the <a href="#mime-type">MIME type</a> of a
Received on Thursday, 10 September 2009 09:53:42 UTC