<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xml:base="https://www.webmaster-forums.net/crss/node/1043039" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title></title>
    <link>https://www.webmaster-forums.net/crss/node/1043039</link>
    <description></description>
    <language>en</language>
          <item>
    <title>You need to submit the form,</title>
    <link>https://www.webmaster-forums.net/html-css-and-javascript/onchange-and-javascript#comment-1238139</link>
    <description> &lt;p&gt;You need to submit the form, either with a submit button or some event that triggers &quot;order.submit()&quot;&lt;/p&gt;
&lt;p&gt;OnChange does not occur when the change is made, but rather when a change is made AND the field loses focus&lt;/p&gt;
&lt;p&gt;1. you can add a listener that stores the quantity number and updates if it is changed - that is moderately advanced JS, involving timers and such&lt;/p&gt;
&lt;p&gt;2. you could add an &quot;Update&quot; button that does not need to do anything really, just remove focus from the form field - this is the easiest solution&lt;/p&gt;
&lt;p&gt;3.  could use a drop-down list for the quantity, so when selected it would trigger onChange - working with select lists is intermediate JS&lt;/p&gt;
&lt;p&gt;I would remove the onChange method from the other fields anyway - in fact, to prevent someone from changing the total, for example, I would add&lt;/p&gt;
&lt;p&gt;&lt;code&gt;onFocus=&amp;quot;this.blur()&amp;quot;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;which pretty much prevents tampering with the text field&lt;/p&gt;
&lt;p&gt;additionally, I would make the defaults show onload for 1 mp3 (set them in the value=&quot;&quot;)&lt;/p&gt;
&lt;p&gt;&lt;em&gt;other TWF members will now enlighten you about the need to verify and sanitize your form inputs... I agree, but that is another issue, &lt;strong&gt;once you have the damn thing working!&lt;/strong&gt;&lt;/em&gt; &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/wink.png&quot; title=&quot;Wink&quot; alt=&quot;Wink&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
 </description>
     <pubDate>Thu, 12 Feb 2009 17:19:06 +0000</pubDate>
 <dc:creator>decibel.places</dc:creator>
 <guid isPermaLink="false">comment 1238139 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>I did the changes and it</title>
    <link>https://www.webmaster-forums.net/html-css-and-javascript/onchange-and-javascript#comment-1238135</link>
    <description> &lt;p&gt;I did the changes and it work. The data in the form is not updating according to the orderUpdate() function. I feel that the code is write. I have tested the PHP info() code and it works perfectly.&lt;/p&gt;
 </description>
     <pubDate>Thu, 12 Feb 2009 16:20:31 +0000</pubDate>
 <dc:creator>busman</dc:creator>
 <guid isPermaLink="false">comment 1238135 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>Still I have no joy. I done</title>
    <link>https://www.webmaster-forums.net/html-css-and-javascript/onchange-and-javascript#comment-1238131</link>
    <description> &lt;p&gt;Still I have no joy. I done the necessary changes and it just wont work. Please bear in mind that the PHP code is in a seperate file&lt;/p&gt;
 </description>
     <pubDate>Thu, 12 Feb 2009 16:11:10 +0000</pubDate>
 <dc:creator>busman</dc:creator>
 <guid isPermaLink="false">comment 1238131 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>try removing const:
const</title>
    <link>https://www.webmaster-forums.net/html-css-and-javascript/onchange-and-javascript#comment-1238133</link>
    <description> &lt;p&gt;try removing const:&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;const mp3 = 0.95;&lt;br /&gt;const VAT = 0.015;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;should be&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;mp3 = 0.95;&lt;br /&gt;VAT = 0.015;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;I do not think &quot;const&quot; is valid JavaScript, it is &quot;reserved for the future&quot; in ECMA&lt;/p&gt;
&lt;p&gt;Also if you declare a variable locally with &quot;var&quot; inside a function, it will wipe out previous instances/values every time the function is called. You can safely remove &quot;var &quot;.&lt;/p&gt;
&lt;p&gt;If you need to initialize a variable, do it globally with var outside the function.&lt;/p&gt;
&lt;p&gt;In JavaScript it is not necessary to declare variables with var, but it is considered good programming form.&lt;/p&gt;
 </description>
     <pubDate>Thu, 12 Feb 2009 15:57:04 +0000</pubDate>
 <dc:creator>decibel.places</dc:creator>
 <guid isPermaLink="false">comment 1238133 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>I have done changes and it</title>
    <link>https://www.webmaster-forums.net/html-css-and-javascript/onchange-and-javascript#comment-1238132</link>
    <description> &lt;p&gt;I have done changes and it wont work.&lt;/p&gt;
 </description>
     <pubDate>Thu, 12 Feb 2009 15:46:01 +0000</pubDate>
 <dc:creator>busman</dc:creator>
 <guid isPermaLink="false">comment 1238132 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>two potential problems jump</title>
    <link>https://www.webmaster-forums.net/html-css-and-javascript/onchange-and-javascript#comment-1238128</link>
    <description> &lt;p&gt;two potential problems jump out:&lt;/p&gt;
&lt;p&gt;1. if you place PHP code in a html page, make sure your server settings allow that &lt;a href=&quot;http://php.about.com/od/advancedphp/p/html_php.htm&quot;&gt;PHP in HTML with .htaccess&lt;/a&gt; - you could also place the PHP code in a .php page&lt;/p&gt;
&lt;p&gt;one way to test: add the phpinfo() function and see if you get the output:&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;phpinfo&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;();&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;2. your form field is named &quot;vat&quot; but your POST variable is for &quot;tax&quot;&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;nbsp; width=&amp;quot;150&amp;quot;&amp;gt;VAT:&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;vat&amp;quot; id=&amp;quot;tax&amp;quot; value=&amp;quot;&amp;quot; onChange=&amp;quot;orderUpdate();&amp;quot;&amp;nbsp; /&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&lt;br /&gt;$vat = $_POST[&amp;#039;tax&amp;#039;];&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;
 </description>
     <pubDate>Thu, 12 Feb 2009 15:19:53 +0000</pubDate>
 <dc:creator>decibel.places</dc:creator>
 <guid isPermaLink="false">comment 1238128 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>You need to enclose code in</title>
    <link>https://www.webmaster-forums.net/html-css-and-javascript/onchange-and-javascript#comment-1238127</link>
    <description> &lt;p&gt;You need to enclose code in the code tags, use the 3rd icon from the right in the toolbar:&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;title&amp;gt;Untitled Document&amp;lt;/title&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;script language=&amp;quot;javascript&amp;quot; type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;!--&lt;br /&gt;	function orderUpdate(){&lt;br /&gt;	const mp3 = 0.95;&lt;br /&gt;	const VAT = 0.015;&lt;br /&gt;	&lt;br /&gt;	var mptune = parseInt(document.getElementById(&amp;quot;songs&amp;quot;).value);&lt;br /&gt;	 if(isNaN(mptune))&lt;br /&gt;	&amp;nbsp; mptune = 0;&lt;br /&gt;	var subTotal = mptune * mp3;&lt;br /&gt;	var taxes = subTotal * VAT;&lt;br /&gt;	var total = subTotal + taxes;&lt;br /&gt;	document.getElementById(&amp;quot;subtotal&amp;quot;).value = &amp;quot;£&amp;quot; + subTotal.toFixed(2);&lt;br /&gt;	document.getElementById(&amp;quot;tax&amp;quot;).value = &amp;quot;£&amp;quot; + taxes.toFixed(2);&lt;br /&gt;	document.getElementById(&amp;quot;total&amp;quot;).value = &amp;quot;£&amp;quot; + total.toFixed(2);&lt;br /&gt;	}&lt;br /&gt;--&amp;gt;&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;form name=&amp;quot;order&amp;quot; action=&amp;quot;tune.php&amp;quot; method=&amp;quot;POST&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;table border=&amp;quot;0&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;nbsp; colspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot;&amp;gt;Mp3 in your Cart&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;nbsp; colspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot;&amp;gt;Cost per mp3 0.95p&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;nbsp; width=&amp;quot;150&amp;quot;&amp;gt;# of singles:&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;mp&amp;quot; id=&amp;quot;songs&amp;quot; value=&amp;quot;&amp;quot; onChange=&amp;quot;orderUpdate();&amp;quot;&amp;nbsp; /&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;nbsp; width=&amp;quot;150&amp;quot;&amp;gt;Sub Total:&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;subtotal&amp;quot; id=&amp;quot;subTot&amp;quot; value=&amp;quot;&amp;quot; onChange=&amp;quot;orderUpdate();&amp;quot;&amp;nbsp; /&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;nbsp; width=&amp;quot;150&amp;quot;&amp;gt;VAT:&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;vat&amp;quot; id=&amp;quot;tax&amp;quot; value=&amp;quot;&amp;quot; onChange=&amp;quot;orderUpdate();&amp;quot;&amp;nbsp; /&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;nbsp; width=&amp;quot;150&amp;quot;&amp;gt;Total:&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;total&amp;quot; id=&amp;quot;total&amp;quot; value=&amp;quot;&amp;quot; onChange=&amp;quot;orderUpdate();&amp;quot;&amp;nbsp; /&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;/table&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;br /&gt;&lt;br /&gt;This is the PHP code for the &amp;lt;form&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;html&amp;gt;&lt;br /&gt; &amp;lt;body&amp;gt;&lt;br /&gt;	&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $subtotal &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_POST&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;subtotal&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;];&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$vat &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_POST&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;tax&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;];&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$total &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_POST&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;total&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;];&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$subtotal&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$vat&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$total&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt; &amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;
 </description>
     <pubDate>Thu, 12 Feb 2009 15:10:52 +0000</pubDate>
 <dc:creator>decibel.places</dc:creator>
 <guid isPermaLink="false">comment 1238127 at https://www.webmaster-forums.net</guid>
  </item>
  </channel>
</rss>
