2017-04-19 80 views
1

我有三個下拉列表和幾個文本輸入,第一個下拉菜單用於隱藏某些輸入,不需要顯示,第二個下拉菜單用於重新加載頁面並使第三個下拉菜單向下取第二個下拉選項中的數據庫庫中的信息。現在,當我單擊第二個下拉菜單,頁面重新加載以及輸入隱藏在下拉菜單1再次顯示時,我面臨一個問題....更新後隱藏內容

重裝後

代碼中獲取價值:

<?php 
@$utm=$_GET['utm']; // Use this line or below line if register_global is off 
if(strlen($utm) > 0 and !is_numeric($utm)) 
{ // to check if $utm is numeric data or not. 
echo "Data Error"; 
exit; 
} 
@$gpotp=$_GET['gpotp']; 
if(strlen($gpotp) > 0 and !is_numeric($gpotp)) 
{ 
echo "Data Error"; 
exit; 
} 
?> 

JavaScript來隱藏內容(通過下拉致電1):

<script> 
    function jsFunction(value) 
{ 
var p = document.getElementById('ps'); 
var r = document.getElementById('rps'); 
var u = document.getElementById('upoint'); 
var m = document.getElementById('umng'); 
var t = document.getElementById('tmpass'); 
if ((value) == '1') 
{ 
    p.style.display = ''; 
    r.style.display = ''; 
    u.style.display = 'none'; 
    m.style.display = 'none'; 
    t.style.display = 'none'; 
} 
else if ((value) == '2') 
{ 
    p.style.display = 'none'; 
    r.style.display = 'none'; 
    u.style.display = ''; 
    m.style.display = 'none'; 
    t.style.display = ''; 
} 
if ((value) == '3') 
{ 
    p.style.display = 'none'; 
    r.style.display = 'none'; 
    u.style.display = ''; 
    m.style.display = ''; 
    t.style.display = ''; 
} 

} 
</script> 

代碼重新加載頁面(調用時下拉2):

function reload(form) 
{ 

var val=form.utm.options[form.utm.options.selectedIndex].value; 
var va2=form.gpotp.options[form.gpotp.options.selectedIndex].value; 
self.location='CrtGroup.php?utm=' + val +'&gpotp=' + va2 ; 

} 

下拉1:

<select name='gpotp' class='form-control' onmousedown=\"this.value='';\" onchange=\"jsFunction(this.value);\"> 
         <option disabled selected value> -- select an option -- </option>"; 
         if($stmt = $conn->query("$query3")) 
         { 
          while ($row2 = $stmt->fetch_assoc()) 
          { 
          if($row2['Group_ID'][email protected]$gpotp){echo "<option selected value='$row2[Group_ID]'>$row2[Group_Cat]</option>";} 
         else{echo "<option value='$row2[Group_ID]'>$row2[Group_Cat]</option>";} 
          } 
         }else 
         { 
         echo $conn->error; 
         } 
    echo"</select> 

下拉2:

echo"<select class='form-control' onchange=\"reload(this.form)\" name='utm' onmousedown=\"this.value='';\">"; 
         echo"<option disabled selected value> -- select an option -- </option>"; 

         if($stmt = $conn->query("$query2")) 
         { 
          while ($row2 = $stmt->fetch_assoc()) 
          { 
          if($row2['Group_ID'][email protected]$utm){echo "<option selected value='$row2[Group_ID]'>$row2[Tm_GroupID]</option>";} 
         else{echo "<option value='$row2[Group_ID]'>$row2[Tm_GroupID]</option>";} 
          } 
         }else 
         { 
         echo $conn->error; 
         } 

     echo"</select>"; 

下拉3:

echo"<select class='form-control' name='umn' >"; 
         echo"<option disabled selected value> -- select an option -- </option>"; 

         if(isset($utm) and strlen($utm) > 0){ 
         if($stmt = $conn->prepare("SELECT DISTINCT Mng_GroupID,Group_ID,Tm_GroupID FROM mnggroup where Tm_GroupID=? order by Mng_GroupID")) 
         { 
         $stmt->bind_param('i',$utm); 
         $stmt->execute(); 
         $result = $stmt->get_result(); 
         while ($row1 = $result->fetch_assoc()) { 
          echo "<option value='$row1[Group_ID]'>$row1[Mng_GroupID]</option>"; 
          } 

         }else{ 
         echo $conn->error; 
         } 

         ///////// 
         }else{ 
         /////// 
         $query="SELECT DISTINCT Mng_GroupID,Group_ID,Tm_GroupID FROM mnggroup order by Mng_GroupID"; 

         if($stmt = $conn->query("$query")){ 
          while ($row1 = $stmt->fetch_assoc()) { 

         echo "<option value='$row1[Group_ID]'>$row1[Mng_GroupID]</option>"; 

          } 
         }else{ 
         echo $conn->error; 
         } 

         } 

        echo"</select>"; 
+0

請只發布相關的代碼。 –

+1

您需要跟蹤本地存儲或cookies。 –

+0

@DanPhilip現在我的問題是真正與我發佈的所有代碼有關。因爲它的每個部分可能會影響其他代碼 –

回答

0

您可以使用window.name存儲重新加載後仍然存在的標誌。

沒有鏈接,請原諒我,但您可以使用它來代替本地存儲或Cookie,以便在頁面重新加載後簡單實現隱藏所需內容的邏輯。 Es .:

if (window.name === "hide") { 
    element.style.display = "none"; 
} 
+0

如何使用window.name?有任何示例鏈接? –

+0

https://www.w3schools.com/jsref/prop_win_name.asp –