Add two number from two textbox and disply result in third text box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dibyenduk
    New Member
    • Jul 2012
    • 1

    Add two number from two textbox and disply result in third text box

    I want to display result of addition of two number from two text box into third text box. the code must write in php script. i mean how do i assign value of variable to textbox dynamically.
  • lyodmichael
    New Member
    • Jul 2012
    • 75

    #2
    use post,

    example: $_POST['textbox1']

    read this: http://www.html-form-guide.com/php-f...form-post.html

    #tip

    Comment

    • computerfox
      Contributor
      • Mar 2010
      • 276

      #3
      You could also use JavaScript. If it's a simple little form, you can do something like:

      Code:
      <script>
         function getText3(){
            var in1=document.getElementById('in1').value;
            var in2=document.getElementById('in2').value;
            var in3=in1+in2;
            document.getElementById('in3').value=in3;
         }
      </script>
      And then the form should be something like:

      Code:
      <form>
         <input type="text" id="in1"/>
         <input type="text" id="in2"/>
          <input type="text" id="in3"/>
         <button type="button" onclick="getText3()">Get text 3</button>
      </form>
      Thoughts?

      Comment

      • kapil yadav
        New Member
        • Jan 2017
        • 1

        #4
        simple form

        <html>
        <head>
        <title>My Page</title>
        </head>
        <body>
        <br>
        <form name="myform" action="textent ry2.php" method="POST">
        <input type="submit" name="submit" value = "go">
        <input type="text" name="text1" onkeyup="calc() ">
        <input type="text" name="text2" onkeyup="calc() ">
        <input type="text" name="text3" >
        </form>
        <script>
        function calc()
        {
        var elm = document.forms["myform"];

        if (elm["text1"].value != "" && elm["text2"].value != "")
        {elm["text3"].value = parseInt(elm["text1"].value) - parseInt(elm["text2"].value);}
        }
        </script>
        </body>
        </html>

        Comment

        Working...