over 10 years ago
The code below will help, how one can use selector "class" to sum all the values in different input box in a Form.
<pre><pre>&lt;pre&gt;&amp;lt;script language="javascript"&amp;gt; function sumupall(className, div){ var elements = document.getElementsByClassName(className); var sum = 0; for(var i = 0; i &amp;lt; elements.length; ++i){ sum += parseInt(elements[i].value); } document.getElementById('totalsum').innerHTML = "Total : " + sum; } &amp;lt;/script&amp;gt; &amp;lt;input type="text" name="box1" class="textbox" value="2" /&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;input type="text" name="box2" class="textbox" value="-3" /&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;input type="text" name="box3" class="textbox" value="-3" /&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;input type="text" name="box4" class="textbox" value="8" /&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;input type="submit" name="sum" id="sum" value="Total" onclick="sumupall('textbox', 'totalsum')" /&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;div id="totalsum"&amp;gt;&amp;lt;/div&amp;gt; &lt;/pre&gt; </pre> </pre>
Starting with Chrome version 45, NPAPI is no longer supported for Google Chrome. For more information, see Chrome and NPAPI (blog.chromium.org).
Firefox and Microsoft Internet Explorer are recommended browsers for websites using java applets.
Chrome Version Support
Are you sure, you want to delete this comment?
Sign up using
0 Comment(s)