Hi all,

I have three text boxes and I want to place a value in textbox 1 and 2,then add them together and get the result in textbox 3.With the below code I can get it to exho out onto the screen,but If I omit the echo then nothing happens after placeing numbers in T1 andT2.
Can anybbody tell me what I am doing wrong.
Kind Regards
Biggles

<html>
<head>
<title>My Page</title>
</head>
<body>
<br>
<form name="myform" action="textentry2.php" method="POST">
<input type = "submit" name = "submit" value = "go">
<input type = "text" name = "text1" >
<input type = "text" name = "text2" >
<input type = "text" name = "text3" >
<?php

$text_entry = $POST['text1'];
$text_entry2 = $
POST['text2'];
$text_entry3 = $_POST['text3'];
{

$text_entry3 = ($text_entry2 + $text_entry);
echo ($text_entry3);

}
?>

    Hi there Biggles,

    While + works great on numbers, it's not for combining the display of variables. Give this a shot:

    $text_entry3 = ($text_entry2 . $text_entry);

    See if that fixes you up.

      Hi schwin,
      Many thanks for the reply.The two variables add up nicely but the sum appears on the form and not in the third text box,hence my equation $text_entry3 = ($text_entry2 + $text_entry);:queasy:The idea was to place the sum of T1 and T2 into T3...well that was the plan๐Ÿ˜ƒ
      Kind Regards
      Biggles

        <html>
        <head>
        <title>My Page</title>
        </head>
        <body>
        <?php
        $text_entry1 = $_POST['text1'];
        $text_entry2 = $_POST['text2'];
        // why do you want the POST value of text3 if it's a sum of two others?
        //$text_entry3 = $_POST['text3'];
        
        $text_entry3 = $text_entry1 + $text_entry2;
        
        
        ?>
        <br>
        <form name="myform" action="textentry2.php" method="POST">
        <div>
        <input type = "submit" name = "submit" value = "go">
        <input type = "text" name = "text1" value="<?php echo $text_entry1 ?>">
        <input type = "text" name = "text2" value="<?php echo $text_entry2 ?>">
        <?php 
        echo ' The sum: ',$text_entry3 ;
        ?>
        </div>
        </form> 

          Just try bellow mention code:

          <input id="text1" type="text" name="text1" />
          <input id="text2" type="text" name="text2" />
          <input id="text3" type="text" name="text3" onClick="sum()"/>

          <script type="text/javascript">
          function sum()
          {
          document.getElementById('text3').value = parseInt(document.getElementById('text1').value) + parseInt(document.getElementById('text2').value);
          }
          </script>

            Write a Reply...