2016-07-04 7 views
0

Alle PHP-Experten: Ich bin ein Anfänger. Ich habe diese Referenzelektrode Converter:Dropdown-Menü ist seltsam

<!DOCTYPE html> 
<html> 
    <head> 
     <title>Referance Electrode Converter</title> 
     <link rel="stylesheet" href="css/style.css"> 
    </head> 
    <body> 
     <h1>Referance Electrode Converter</h1> 
     <h6>After Pressing Convert The Dropdown Goes Back to It's Defaults</h6> 
     <form action="index.php" method="get"> 
      <input type="text" name="input" placeholder="Enter Amount"></input> 
      <select name="dropdown"> 
       <option value="SHE" selected><sub>SHE</sub></option> 
       <option value="SCE"><sub>SCE</sub></option> 
       <option value="AG"><sub>Ag/AgCl</sub></option> 
       <option value="MSE">MSE</option> 
       <option value="CSE">CSE</option> 
      </select> 
      <br /> 
      <?php 

$cc_input = $_GET['input']; 
$cc_dropdown = $_GET['dropdown']; 
$cc_odropdown = $_GET['odropdown']; 

if(isset($_GET['sbmt'])) 
{ 
    if($cc_dropdown == 'SHE') { 
     if($cc_odropdown == 'SHE') { 
      $output = $cc_input * 1 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'SCE') { 
      $output = $cc_input + 0.2415 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'AG') { 
      $output = $cc_input + 0.222 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'MSE') { 
      $output = $cc_input - 0.615 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'CSE') { 
      $output = $cc_input - 0.318 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } 
    } 
    elseif($cc_dropdown == 'SCE') { 
     if($cc_odropdown == 'SHE') { 
      $output = $cc_input - 0.2415 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'SCE') { 
      $output = $cc_input * 1 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'AG') { 
      $output = $cc_input + 0.0195 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'MSE') { 
      $output = $cc_input - 0.3735 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'CSE') { 
      $output = $cc_input - 0.765 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } 

    } 
    elseif($cc_dropdown == 'AG') { 
     if($cc_odropdown == 'SHE') { 
      $output = $cc_input - 0.222 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'SCE') { 
      $output = $cc_input - 0.0195; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'AG') { 
      $output = $cc_input * 1 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'MSE') { 
      $output = $cc_input - 0.393 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'CSE') { 
      $output = $cc_input - 0.096 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } 
    } 
    elseif($cc_dropdown == 'MSE') { 
     if($cc_odropdown == 'SHE') { 
      $output = $cc_input + 0.615 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'SCE') { 
      $output = $cc_input + 0.3735 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'AG') { 
      $output = $cc_input + 0.393 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'MSE') { 
      $output = $cc_input * 1 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'CSE') { 
      $output = $cc_input + 0.297 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } 
    } 
    elseif($cc_dropdown == 'CSE') { 
     if($cc_odropdown == 'SHE') { 
      $output = $cc_input + 0.318 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'SCE') { 
      $output = $cc_input + 0.0765 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'AG') { 
      $output = $cc_input + 0.096 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'MSE') { 
      $output = $cc_input - 0.297 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'CSE') { 
      $output = $cc_input * 1 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } 
    } 
} 
      ?> 
      <select name="odropdown"> 
       <option value="SHE"><sub>SHE</sub></option> 
       <option value="SCE" selected><sub>SCE</sub></option> 
       <option value="AG"><sub>Ag/AgCl</sub></option> 
       <option value="MSE">MSE</option> 
       <option value="CSE">CSE</option> 
      </select> 
      <br /> 
      <input type="submit" name="sbmt" value="Convert!"></input> 
     </form> 
    </body> 
</html> 

Das Seltsame ist, dass, wenn ich auf „Konvertieren“, die Drop-Down-Menüs gehen zurück auf das, was die HTML „ausgewählt“ Variable war. Was kann ich tun, um dieses Problem zu beheben?

Dank -Lorelo

+0

Sie müssen nicht verstehen, was Referanse Elektrode ist, denken Sie daran wie Währung – Lorelo

+1

Sie falsch geschrieben "Referenz" in einer zweiten Art jetzt, nur zu sagen ... –

+0

Oh Danke ...... Ich fühle mich jetzt schlecht – Lorelo

Antwort

2

OK, ich bin nicht sicher, ob dies nur ein Problem auf meinem Server, aber es Fehler warf, wenn ich nicht definiert GET-Request-Variablen zu bekommen versucht, also tat ich dies:

Wie auch immer, um das ursprüngliche Problem zu beheben, sollten Sie überprüfen, was die Werte von $ cc_dropdown und $ cc_odropdown sind. Abhängig davon sollten Sie entscheiden, wo das Attribut "selected" ausgegeben werden soll.

UPDATE

Hier ist, was ich getan habe:

... 
    <body> 
    <?php 

if(isset($_GET['input'])) $cc_input = $_GET['input']; 
if(isset($_GET['dropdown'])) $cc_dropdown = $_GET['dropdown']; 
if(isset($_GET['odropdown'])) $cc_odropdown = $_GET['odropdown']; 

    ?> 
     <h1>Referance Electrode Converter</h1> 
     <h6>After Pressing Convert The Dropdown Goes Back to It's Defaults</h6> 
     <form action="index.php" method="get"> 
      <input type="text" name="input" placeholder="Enter Amount"></input> 
      <select name="dropdown"> 
      <?php if(!isset($_GET['sbmt'])): ?> 
       <option value="SHE" selected><sub>SHE</sub></option> 
       <option value="SCE"><sub>SCE</sub></option> 
       <option value="AG"><sub>Ag/AgCl</sub></option> 
       <option value="MSE">MSE</option> 
       <option value="CSE">CSE</option> 
      <?php else: ?> 
       <option value="SHE" <?php if($cc_dropdown=="SHE") echo "selected"; ?> ><sub>SHE</sub></option> 
       <option value="SCE" <?php if($cc_dropdown=="SCE") echo "selected"; ?> ><sub>SCE</sub></option> 
       <option value="AG" <?php if($cc_dropdown=="AG") echo "selected"; ?> ><sub>Ag/AgCl</sub></option> 
       <option value="MSE" <?php if($cc_dropdown=="MSE") echo "selected"; ?> >MSE</option> 
       <option value="CSE" <?php if($cc_dropdown=="CSE") echo "selected"; ?> >CSE</option> 
      <?php endif; ?> 
      </select> 
      <br /> 
      <?php 

if(isset($_GET['sbmt'])) 
{ 
     ... 

UPDATE 2

ich, dass Sie dies auch tun müssen, für die andere Dropdown-Liste vergessen zu erwähnen. Dies ist nur für den oberen. Mach dir keine Sorgen, es ist analog.

+0

Only Für dich. Ich habe keine Fehler. – Lorelo

+0

Verwenden Sie PHP 7 oder 5? – Lorelo

+0

Dies ist die Antwort, arbeitete an der gleichen Sache – Nick