Guest Lady Canti Posted February 5, 2006 Share Posted February 5, 2006 I'm making a calculator for a site, and I need some help with it.The problem is, I have to make it so two items are calculated at one time, whilst also one of the items is names from a chatbox.Basically, I need to have (A • B) and (A • C) in the same statement.My current code is this: <html><title>Woodcutting Calculator!</title><body><form>Number of Logs Cut: <input type="text" name="Number of Logs Cut"><br>Sold at: <input type="text" name="Sold at"><br>Type of Tree Cut: <select name="Type of Tree"><option value="Normal">Normal<!-- Normal is equal to 25 --><option value="Oak">Oak<!-- Oak is equal to 37.5 --><option value="Willow">Willow<!-- Willow is equal to 62.5 --><option value="Teak">Teak<!-- Teak is equal to 85 --><option value="Maple">Maple<!-- Maple is equal to 100 --><option value="Mahogany">Mahogany<!-- Mahogany is equal to 125 --><option value="Yew">Yew<!-- Yew is equal to 175 --><option value="Magic">Magic<!-- Magic is equal to 250 --></select><br><input type="button" value="Calculate!"></form></body></html> The comments say how much they are worth, just to remind me, and tell you.What I need is...The number of logs cut multiplied by amount sold for.The number of logs cut multiplied by the number for the word in the drop-down box.I need these to appear on the same page, as it is a calculator ;dCan anyone help with this? Link to comment Share on other sites More sharing options...
scott100 Posted February 5, 2006 Share Posted February 5, 2006 This shoud do what you asked for I put it into a table aswell to make it a bit neaterIf you want to perform calculations on your page then it would be a good idea for you to learn a scripting language like javascript... <html><head><title>Woodcutting Calculator!</title><script language="JavaScript">function calculate(){var a=0;var b=0;var LC=document.getElementById('LogsCut').value;var SA=document.getElementById('SoldAt').value;a=LC*SA;document.getElementById('Total1').value="£ "+a.toFixed(2); var Tree=document.getElementById('TreeType').value;if (Tree=="Normal")b=25;else if (Tree=="Oak")b=37.5;else if (Tree=="Willow")b=62.5;else if (Tree=="Teak")b=85;else if (Tree=="Maple")b=100;else if (Tree=="Mahogany")b=125;else if (Tree=="Yew")b=175;else if (Tree=="Magic")b=250;else alert("Problems with dropdown");b=b*LCdocument.getElementById('Total2').value="£ "+b.toFixed(2); }</script></head><body><form><table border="0"><tr><td>Number of Logs Cut: </td><td><input type="text" id="LogsCut"><td></tr><tr><td>Sold at: </td><td><input type="text" id="SoldAt"></td></tr><tr><td>Type of Tree Cut:</td><td><select id="TreeType"><option value="Normal">Normal<!-- Normal is equal to 25 --><option value="Oak">Oak<!-- Oak is equal to 37.5 --><option value="Willow">Willow<!-- Willow is equal to 62.5 --><option value="Teak">Teak<!-- Teak is equal to 85 --><option value="Maple">Maple<!-- Maple is equal to 100 --><option value="Mahogany">Mahogany<!-- Mahogany is equal to 125 --><option value="Yew">Yew<!-- Yew is equal to 175 --><option value="Magic">Magic<!-- Magic is equal to 250 --></select></td></tr><td><td> </td></tr><tr><td colspan="2"><input type="button" value="Calculate!" onclick="calculate()"></td></tr><td><td> </td></tr><tr><td>Number of Logs Cut x Sold at: </td><td><input type="text" id="Total1"><td></tr><tr><td>Sold at x Type of Tree Cut: </td><td><input type="text" id="Total2"></td></tr><table></form></body></html> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now