Jump to content

Generating two random numbers in a texarea and adding their values.


knoahg

Recommended Posts

Hi people im still a begginer in PHP this is the code i have so far and it only accepts entering values and adding with the button. So how can i generate two random numbers on the two boxes and calculate the result.

Thank You.

 

<form name="form1" method="post" action="">

  value1:

    <label>

  <input type="text" name="value1">

  </label>

  <p> </p>

  <p>

    <label>

    value2: 

    <input type="text" name="value2">

    </label>

  </p>

 

 

  <p>

    <label>

    <input type="submit" name="submit" value="calculate">

    </label>

</form>

<?php

$_POST[calculate] =="add"; {

$result = $_POST[value1] + $_POST[value2];

}

echo $result;

?>

 

 

[attachment deleted by admin]

You can do it like this:

 

<form name="form1" method="post" action="">
   value1: 
     <label>
  <input type="text" name="value1" value="<?php echo rand(0, 1000000); ?>">
  </label>
  <p> </p>
  <p>
    <label>
    value2:  
    <input type="text" name="value2" value="<?php echo rand(0, 1000000); ?>">
    </label>
  </p>


  <p>
    <label>
    <input type="submit" name="submit" value="calculate">
    </label>
   </form>
<?php
if($_POST[calculate] == "add"){
$result = $_POST['value1'] + $_POST['value2'];
}
echo $result;
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.