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 Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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> Quote Link to comment Share on other sites More sharing options...
CaptainHasman Posted May 14, 2010 Author Share Posted May 14, 2010 Perfect!! Thank you so much! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.