Friday, 13 April 2018

WT-Slip21


21) Design a HTML form to accept two numbers from the user. Give options to choose the
arithmetic operation (use radio buttons). Write a PHP function to display the result on the next
form. (Use the concept of function and default parameters)

Slip21.html                                                                                              

<html><body><form action="cal.php"method="post">
Number 1:<input type="text"name="no"><br>
Number 2:<input type="text"name="no2"><br>
<br>
<input type="radio"name="calc"value="add">ADD<br>
<input type="radio"name="calc"value="subtract">Subtract<br>
<input type="radio"name="calc"value="mult">Product<br>
<input type="radio"name="calc"value="div">Division<br>
<input type="submit"value="submit">
</form>
</body></html>

cal.php

<html>
<body>
<?php
function add($no=0,$no2=1)
{
$sum=$no+$no2;
echo "$sum<br>";
}
function subtract($no=1,$no2=2)
{
$sub=$no-$no2;
echo "$sub<br>";
}
$n=$_POST['no'];
$n2=$_POST['no2'];
$c=$_POST['calc'];
if($c=="add")
{
add($n,$n2);
echo"<br>";
echo "Call with default value";
add();
}

if($c=="subtract")
{
subtract($n,$n2);
echo"<br>";
echo "Call with default value";
subtract();
}
?>
</body> </html>