Jump to content

2 drop down lists - only 1 works..


CageyJ0nnY

Recommended Posts

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

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.