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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.