CageyJ0nnY Posted October 27, 2009 Share Posted October 27, 2009 the idea behind this document is that it can convert imperial to metric and vise versa. Ive used drop down lists to enable the user to switch between Kilogram, centimetres ect. The other allows it to be converted the other way, however only the first drop down list works. here's the HTML page <html> <head> <title>Imperial to Metric</title> </head> <body> <form method="post" action="converter.php"> <input name = "number1" type="text"> <select name = "operator"> <option value = "Kilometres">Kilometres</option> <option value = "Centimetres">Centimetres</option> <option value = "Kilograms">kilograms</option> <option value = "Kilowatts">Kilowatts</option> <option value = "Litres">Litres</option> </select> <p> <input name = "number2" type="text"> <select name = "operator"> <option value = "Mile">Mile</option> <option value = "Inch">Inch</option> <option value = "Pound">Pound</option> <option value = "Horsepower">Horsepower</option> <option value = "Pint">Pint</ption> <input name = "Submit" type = "submit" value="="> </form> </body> </html> and heres the PHP page it links to <?php $kilometres = "1.609"; $centimetres = "2.54"; $kilograms = "0.454"; $kilowatts = "0.746"; $litres = "0.568"; $number1 = $_POST[number1]; $operator = $_POST[operator]; $operator1 = $_POST[operator]; if ($operator=="Kilometres"){ $answer = "$number1 miles equals ".($number1 * 1.609)." kilometres" ; } elseif ($operator == "Centimetres"){ $answer = "$number1 inches equals ".($number1 * 2.54)." centimetres" ; } elseif ($operator == "Kilograms"){ $answer = "$number1 Pounds equals ".($number1 * 0.454)." Kilograms" ; } elseif ($operator == "Kilowatts"){ $answer = "$number1 horsepower equals ".($number1 * 0.746)." Killowatts" ; } else{ $answer = "$number1 pints equals ".($number1 * 0.568). " litres" ; } echo "$answer"; if ($operator1=="Mile"){ $answer2 = "number2 kilometres equals ".($number2 * 0.621)." Miles" ; } else if $operator1 == "Inches"){ $answer2 = "$number2 centimetres equals ".($number2 * 0.393)." Inches" ; } else if $operator1 == "Pound"){ $answer2 = "$number2 kilograms equals ".($number2 * 2.204)." Pound" ; } else if $operator1 == "Horsepower"){ $answer2 = "$number2 Kilowatts equals ".($number2 * 1.34)." Horsepower" ; else{ $answer2 litres equals ".($number * 1.76). " Pints ; } echo "$answer2"; ?> thanks John Quote Link to comment https://forums.phpfreaks.com/topic/179220-2-drop-down-lists-only-1-works/ Share on other sites More sharing options...
MadTechie Posted October 27, 2009 Share Posted October 27, 2009 you forgot to add $number2 = $_POST['number2']; also you have operator in the form twice.. that won't work correctly Quote Link to comment https://forums.phpfreaks.com/topic/179220-2-drop-down-lists-only-1-works/#findComment-945574 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.