how to add two text box values?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nirmalsingh
    New Member
    • Sep 2006
    • 218

    #1

    how to add two text box values?

    how to add two text box values?refer my code below. it is concatinating instead of adding. my code is
    Code:
    <html>
    <head>
    <script language="javascript">
    function addone()
    {
    a=document.getElementById("h1").value
    
    var b=a+1;
    document.getElementById("h1").value=b;
    
    }
    </script>
    </head>
    <body>
    
    <input type="text" id="h1"/>
    <input type="button" value="ADD" onclick="addone()"/>
    </body>
    </html>
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Use parseInt:
    Code:
    var b = parseInt(a)+1;

    Comment

    Working...