PHP how to make the value of the result display in textbox

Shauiosbhaoiu Aousiguosba

I have 4 radio buttons +, -, *, / and I am planning to do if I select + it will add the result of the two textbox and display it to the 3rd texbox and so if I select - sign it will minus the two texbox and display it to the 3rd textbox and so on. Any help with this would be appreciated. this is the picture

 <html>
    <body>
    <?php
      function add($x,$y){

           $add=$x + $y;
           return $add;

       }
       function subtract($x,$y){

           $subtract=$x - $y;
           return $subtract;

       }
       function multiply($x,$y){

           $multiply=$x * $y;
           return $multiply;

       }
       function divide($x,$y){

           $divide=$x / $y;
           return $divide;

       }

    ?>
    <form action="#" method="post">
    Num1:<input name="num1"><br>
    <input type='radio'  name='express' value='add'>+
    <input type='radio'  name='express' value='subtract'>-
    <input type='radio'  name='express' value='multiply'>*
    <input type='radio'  name='express' value='divide'>/
    <br>
    Num2:<input name="num2"> 
    Result<input value='<?php



    ?>'>
    <input type="submit" name="submit">
    </form>
    <?php


       if(isset($_POST['submit'])){
           $x=$_POST['num1'];
           $y=$_POST['num2'];
           $z=$_POST['express'];
           if($z == 'add'){
               echo add($x,$y);  
           }
           else if($z=='subtract'){
               echo subtract($x,$y);

           }
           else if($z=='multiply'){
               echo multiply($x,$y);

           }
           else{
               echo divide($x,$y);

           }

       }

    ?>
    </body>
    </html>
jayxhj
<html>
<body>
<?php
   $Result = '';

   if(isset($_POST['submit'])){
       $num1    = $_POST['num1'];
       $num2    = $_POST['num2'];
       $express = $_POST['express'];
       switch ($express) {
        case 'add':
           $Result = $num1 + $num2;
           break;

        case 'subtract':
           $Result = $num1 - $num2;
           break;

        case 'multiply':
           $Result = $num1 * $num2;
           break;

        case 'divide':
           if(0 != $num2 ){
            $Result = $num1 / $num2;
          }
          break;

         default:
           break;
       }  

   }

?>
<form action="#" method="post">
Num1:<input name="num1"><br>
<input type='radio'  name='express' value='add'>+
<input type='radio'  name='express' value='subtract'>-
<input type='radio'  name='express' value='multiply'>*
<input type='radio'  name='express' value='divide'>/
<br>
Num2:<input name="num2"> 
Result<input value='<?php echo $Result;?>'>
<input type="submit" name="submit">
</form>
</body>
</html>

I suggest you achieve it by using JavaScript and separate the PHP code from HTML code.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

PHP how to make the value of the result display in textbox

From Dev

how to make array result the value of a link in php

From Dev

Display iframe value at textbox in php

From Dev

want help in textbox condition to display value in php

From Dev

display result of an if statement in a textbox

From Dev

How to Show Final Result in a Main Textbox Value

From Dev

How to Display value of textbox in label in another form?

From Dev

How to display a textbox value in a DIV multiple Times

From Dev

How to Display value of textbox in label in another form?

From Dev

how to get value of cell in table and display it in textbox

From Dev

how to display the entire variable with space in textbox in php

From Dev

How do i display a select stored procedure result in a textbox?

From Dev

How to get the values of multiple select box and display the result in textbox?

From Dev

How to get the values of multiple select box and display the result in textbox?

From Dev

How to split textbox value then display splitted value on label

From Dev

how to display the result of the search in a table using php

From Dev

How can I make a textBox value equal to a datagrivew cell value

From Dev

json how to make the result to alter as expected value

From Dev

How can display message after entering value in textbox with the help of jquery?

From Dev

how to display an auto increment value in a textbox using session

From Dev

How to display a textbox in SSRS based on not null value in a column from dataset

From Dev

How to make a button in C# Make a text file and add the result of a textbox to it and then show it in the program?

From Dev

Save checkbox value to array and display result PHP, Jquery

From Dev

php loop display result if isset and matches the given value

From Dev

how to make password textbox value visible when hover an icon

From Dev

How to make multiple dependent TextBox on Dropdown value from database in jsp

From Dev

How to make multiple dependent TextBox on Dropdown value from database in jsp

From Dev

VBA - How to retrieve value from one TextBox and make it appear in another?

From Dev

How to make a Haskell program display a preliminary result in response to user input?

Related Related

  1. 1

    PHP how to make the value of the result display in textbox

  2. 2

    how to make array result the value of a link in php

  3. 3

    Display iframe value at textbox in php

  4. 4

    want help in textbox condition to display value in php

  5. 5

    display result of an if statement in a textbox

  6. 6

    How to Show Final Result in a Main Textbox Value

  7. 7

    How to Display value of textbox in label in another form?

  8. 8

    How to display a textbox value in a DIV multiple Times

  9. 9

    How to Display value of textbox in label in another form?

  10. 10

    how to get value of cell in table and display it in textbox

  11. 11

    how to display the entire variable with space in textbox in php

  12. 12

    How do i display a select stored procedure result in a textbox?

  13. 13

    How to get the values of multiple select box and display the result in textbox?

  14. 14

    How to get the values of multiple select box and display the result in textbox?

  15. 15

    How to split textbox value then display splitted value on label

  16. 16

    how to display the result of the search in a table using php

  17. 17

    How can I make a textBox value equal to a datagrivew cell value

  18. 18

    json how to make the result to alter as expected value

  19. 19

    How can display message after entering value in textbox with the help of jquery?

  20. 20

    how to display an auto increment value in a textbox using session

  21. 21

    How to display a textbox in SSRS based on not null value in a column from dataset

  22. 22

    How to make a button in C# Make a text file and add the result of a textbox to it and then show it in the program?

  23. 23

    Save checkbox value to array and display result PHP, Jquery

  24. 24

    php loop display result if isset and matches the given value

  25. 25

    how to make password textbox value visible when hover an icon

  26. 26

    How to make multiple dependent TextBox on Dropdown value from database in jsp

  27. 27

    How to make multiple dependent TextBox on Dropdown value from database in jsp

  28. 28

    VBA - How to retrieve value from one TextBox and make it appear in another?

  29. 29

    How to make a Haskell program display a preliminary result in response to user input?

HotTag

Archive