VB icon

Calculator in PHP using Drop Down Menu

Email
Submitted on: 9/26/2016 12:02:59 AM
By: Jake R. Pomperada  
Level: Beginner
User Rating: By 1 Users
Compatibility: PHP 3.0, PHP 4.0, PHP 5.0
Views: 3845
author picture
 
     A simple calculator program that I wrote in PHP using Drop Down Menu to select the mathematical operator such as addition, subtraction, multiplication and division using combo box in HTML. Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com. My mobile number here in the Philippines is 09173084360.

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Calculator in PHP using Drop Down Menu
// Description:A simple calculator program that I wrote in PHP using Drop Down Menu to select the mathematical operator such as addition, subtraction, multiplication and division using combo box in HTML.
Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com. 
My mobile number here in the Philippines is 09173084360.
// By: Jake R. Pomperada
//**************************************

<html>
<head>
<?php
error_reporting(0);
 
 $a = $_REQUEST['num1'];
 $b = $_REQUEST['num2'];
?>
 
<title>Simple Calculator</title>
</head>
<style type="text/css">
 body
 {
 background-color:yellow;
 font-family:arial;
 font-size:14px;
 font-weight:bold;
 }
 
 #result
 {
 color:green;
 font-family:arial;
 font-size:16px;
 }
 
 
 
 input[type="text"] {
 height: 50px;
 width: 50px;
 font-family:arial;
 font-size:25px;
 font-weight:bold;
}
#opt{
 width:250px;
}
</style>
<script language="javascript">
 function validate_form()
 {
 var num1 = document.entryform.num1;
 var num2 = document.entryform.num2;
 if (num1.value=="" || num1.value==null)
 {
 alert("Please specify value on first box");
 num1.focus();
 return false;
 }
 else if (num2.value=="" || num2.value==null)
 {
 alert("Please specify value on second box");
 num2.focus();
 return false;
 }
 }
</script>
<body>
<?php
if (isset($_REQUEST['clear']))
 {
 $a="";
 $b=""; 
 }
 ?>
<form method="post" onSubmit="return validate_form(this)" name="entryform">
<fieldset>
 <legend>Simple Calculator</legend>
 <input type="text" name="num1" value="<?php echo $b; ?>" autofocus>
 <select name="opt_math">
 <option value="+">+
 <option value="-">-
 <option value="*">*
 <option value="/">/
 </select>
 <input type="text" name="num2" value="<?php echo $a; ?>"><br><br>
 <input type="submit" name="submit" value="Compute">    
<input type="submit" name="clear" value="Clear">
 <br><br>
 
 <span id="result">
 Result is
 <strong>
 <?php
if ($_REQUEST['opt_math']=="+"){
 echo $a+$b;
 }
 else if ($_REQUEST['opt_math']=="-"){
 echo $a-$b;
 }
 else if ($_REQUEST['opt_math']=="/"){
 echo $a/$b;
 }
 else if ($_REQUEST['opt_math']=="*"){
 echo $a*$b;
 }
 
 ?>
 </strong>
 </span><br><br><br>
 </fieldset>
 </form>
 </body>
 </html>


Other 46 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.