Results 1 to 7 of 7

Thread: java script code for addition of two numbers

  1. #1
    Join Date
    Dec 2009
    Posts
    32

    java script code for addition of two numbers

    Hi friends,

    I am coding one java script program. The desired out-put of this java script code should be the addition of the two given numbers. I have one code for this but it doesn't run correctly, so I need your help.
    Please let me know any java script code for addition of two numbers. I Would appreciate your help.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: java script code for addition of two numbers

    Hello friend,

    Use below java script code in your program to print the addition of two numbers:
    HTML Code:
    <script type="text/javascript">
    function AddJavaSc()
    {
      var k, l;
      
      l=parseInt(document.getElementById("txtVal1").value);
      k=parseInt(document.getElementById("txtVal2").value);
      
    document.getElementById("txtVal3").value=l + k;
    
    }
    </script>

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: java script code for addition of two numbers

    Javascript code for addition:
    <Html>
    <head>
    <script language="JAVASCRIPT">
    function addTWONumbers()
    {
    var num1 = parseInt(document.getElementById("num value1").value);
    var num2 = parseInt(document.getElementById("num value2").value);
    var ansD = document.getElementById("Addition");
    ansTD.value = num1 + num2;
    }
    </script>
    </head>
    <Body text ="red">
    numvalue1 = <input type="text" name="numvalue1" id="numvalue1" value="1"/>

    numvalue2 = <input type="text" name="numvalue2" id="numvalue2" value="2"/>

    <input type="Button" value="Click " name="Submit" onclick="javascript:addTWNumbers()"/>

    </Body>
    </html>

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: java script code for addition of two numbers

    Hi,

    To print the addition of two numbers using java script you need to use the one function. First you need to pass two numbers to that java script function. implement the "addition code" in the that function. The function will take two number as input and will give back the addition.
    HTML Code:
    function addDemo(v1, v2)
    {
    ans1.value = v1 + V2
    }

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: java script code for addition of two numbers

    I think you should use the alert function of the javascript to calculate addition. Use something below in you program:
    HTML Code:
    var t = '963';
    
    var y = '852;
    
    var h = parseInt(t) + parseInt(y);
    
    Alert(h); //It will show the addition

  6. #6
    Join Date
    Oct 2005
    Posts
    2,393

    Re: java script code for addition of two numbers

    I have following java script program for addition, copy this java script program and run on your computer:
    HTML Code:
    <HTML>
    <head>
    <title>Addition code</title>
    <script type="text/javascript">
    function AddJS()
    {
      var x=document.getElementById("txtval1").value;
      var z=document.getElementById("txtval2").value;
      document.getElementById("txt3").value=x + z;
    }
    </script>
    </head>
    <body>
    
    B:
    <input id="txtVAl1"type="text" >
    
    N:
    <input id="txtval2"type="text" >
    
    AdditionResult:
    <input id="txtval3" type="text"  >
    
    <input onclick="AddJS()" type="button" id="btnSt" value="Submit" >
    
    </body>
    </HTML>

  7. #7
    Join Date
    Nov 2009
    Posts
    95

    Re: java script code for addition of two numbers

    HTML Code:
    function get_Two_sum()
    {
    
    If (document.getElementById("BNM1").value == "")
    
    document.getElementById("BNM1").value= 0;
    
    If (document.getElementById("BNM2").value == "")
    
    document.getElementById("BNM2").value= 0;
    
    document.getElementById("BNM3").value= parseInt (document.getElementById("BNM1").value) + parseInt (document.getElementById("BNM2").value);
    
    }
    

Similar Threads

  1. help me to understand java code (calendar java code) ?
    By so0oma in forum Software Development
    Replies: 2
    Last Post: 10-01-2011, 12:01 AM
  2. Need C program code to count numbers of negative & positive numbers
    By Sarfaraj Khan in forum Software Development
    Replies: 5
    Last Post: 16-01-2010, 02:00 PM
  3. What is the shell program to calculate addition of two numbers?
    By Shophia_D in forum Software Development
    Replies: 3
    Last Post: 09-12-2009, 02:34 PM
  4. program to sort numbers in java.
    By Balamani in forum Software Development
    Replies: 3
    Last Post: 24-11-2009, 10:18 PM
  5. Java Script Addition Problem
    By Magnus in forum Software Development
    Replies: 3
    Last Post: 01-06-2009, 11:38 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,661,034.42535 seconds with 17 queries