CaptainHasman Posted May 14, 2010 Share Posted May 14, 2010 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 More sharing options...
947740 Posted May 14, 2010 Share Posted May 14, 2010 Based on what you want to do...javascript would be a much better solution. You wouldn't even have to send the user to a new page. Link to comment https://forums.phpfreaks.com/topic/201778-php-calculator/#findComment-1058424 Share on other sites More sharing options...
CaptainHasman Posted May 14, 2010 Author Share Posted May 14, 2010 Thanks man. Excuse my stupidity, but I honestly have no idea how to do that either. I searched Google and DynamicDrive.com for some help, but all I can find are regular calculators. So would you be able to help me out with that then? Link to comment https://forums.phpfreaks.com/topic/201778-php-calculator/#findComment-1058429 Share on other sites More sharing options...
947740 Posted May 14, 2010 Share Posted May 14, 2010 <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 More sharing options...
CaptainHasman Posted May 14, 2010 Author Share Posted May 14, 2010 Perfect!! Thank you so much! Link to comment https://forums.phpfreaks.com/topic/201778-php-calculator/#findComment-1058484 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.