Jump to content

PHP Calculator


CaptainHasman

Recommended Posts

Hi guys. I'm a PHP noob... Like big time.

 

Anyways I need to make a calculator which has options people can select. Those options need to have preset values. And then when the desired options are checked off, the value of those options are added together for a final value.

 

So basically:

 

[  ]  Red (2.00)

[  ]  Blue (4.00)

[  ]  Green (1.00)

 

[ CALCULATE ]

 

So if I hit Red and Green, then pressed calculate, the number 3.00 will show up.

 

Is this an overly complicated script? If I could please get some help or direction with this, I'd much appreciate it.

 

Thank you,

Hasman

Link to comment
https://forums.phpfreaks.com/topic/201778-php-calculator/
Share on other sites

<html>
<head>
<script language='javascript' type='text/javascript'>
function add() {

var total = document.getElementById("total");
var red = document.form.red.value;
var blue = document.form.blue.value;
var green = document.form.green.value;

var sum = 0;
     if(document.form.red.checked == true) {
     var sum = parseInt(red) + sum;
     }
     if(document.form.blue.checked == true) {
     var sum = parseInt(blue) + sum;
     }
     if(document.form.green.checked == true) {
     var sum = parseInt(green) + sum;
     }

total.innerHTML = sum;

}
</script>
</head>
<body>
<form name='form' action='misc.php' method='post'>
<input type='checkbox' name='red' value='2' />
<input type='checkbox' name='blue' value='4' />
<input type='checkbox' name='green' value='1' />
<input type='button' name='Calculate' value='Calculate' onclick='add()' />
</form>
<div id='total'>
</div>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/201778-php-calculator/#findComment-1058434
Share on other sites

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.