Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Total of values in multiple textbox.

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 565
    Comment on it

    The code below will help, how one can use selector "class" to sum all the values in different input box in a Form.

    <pre>&lt;pre&gt;&amp;lt;pre&amp;gt;&amp;amp;lt;script language="javascript"&amp;amp;gt;
    
        function sumupall(className, div){
    
            var elements = document.getElementsByClassName(className);
            var sum = 0;
    
            for(var i = 0; i &amp;amp;lt; elements.length; ++i){
    
                sum += parseInt(elements[i].value);
    
            }
    
            document.getElementById('totalsum').innerHTML = "Total : " + sum;
        }
    &amp;amp;lt;/script&amp;amp;gt;
    &amp;amp;lt;input type="text" name="box1"  class="textbox" value="2" /&amp;amp;gt;&amp;amp;lt;br /&amp;amp;gt;
    &amp;amp;lt;input type="text" name="box2"  class="textbox" value="-3" /&amp;amp;gt;&amp;amp;lt;br /&amp;amp;gt;
    &amp;amp;lt;input type="text" name="box3"  class="textbox" value="-3" /&amp;amp;gt;&amp;amp;lt;br /&amp;amp;gt;
    &amp;amp;lt;input type="text" name="box4"  class="textbox" value="8" /&amp;amp;gt;&amp;amp;lt;br /&amp;amp;gt;
    &amp;amp;lt;input type="submit" name="sum" id="sum" value="Total" onclick="sumupall('textbox', 'totalsum')" /&amp;amp;gt;&amp;amp;lt;br /&amp;amp;gt;
    
    &amp;amp;lt;div id="totalsum"&amp;amp;gt;&amp;amp;lt;/div&amp;amp;gt;
    &amp;lt;/pre&amp;gt;
    &lt;/pre&gt;
    </pre>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: