2015-11-02 81 views
1

我正在複選框列表中,如果勾選了其中一個複選框,則會出現所有複選框。我已經隱藏了PHP的子複選框,但是當我試圖檢查其中一個允許出現所有子複選框的複選框時,它不起作用。無法顯示子複選框

這是我走到這一步,(我用PHP也顯示&連接存儲在數據庫中的主要複選框的列表,你可以看到我用事先準備好的聲明[綁定]):

<form action="avfunc.php" method="POST" class="form-horizontal well"> 
<div id="updatediv"> 
    <input type="submit" name="update" id="update" value="Update Reference" style="width:100px; display:none;" class="edit" /> 
</div> 
<fieldset> 
<div class="row"> 
    <div class="col-lg-3"> 
    </div> 
    <div class="col-lg-6"> 
     <?php 
      $tsql = "select * from medtest"; 
      $tstmt = $con->prepare($tsql); 
      $tstmt->execute(); 
      $tstmt->bind_result($mti,$mtn); 
      $tstmt->store_result(); 

      while ($tstmt->fetch()){ 
        $d1= '<input type="checkbox" name="test" 
        value="'.$mti.'" onClick="var e=document.getElementById("updatediv"); var s=document.getElementById("update"); e.removeChild(s) ; this.form.submit();">'.$mtn.'<br> '; 
        echo $d1; 

      }  

      ?>  
     <?php if($_POST['checkbox'] == "3"){ ?> 
     <h4>Laboratory Examination</h4> 
     <hr> 
     <div class="row"> 
      <div class="col-lg-6"> 
       <div class="col-xs-2"> 
       </div> 
       <div class="col-xs-7"> 
        <div><input type="checkbox" name="topic" value="1"><span>Complete Blood Count</span></div> 
        <div><input type="checkbox" name="topic" value="2"><span>Blood Typing</span></div> 
        <div><input type="checkbox" name="topic" value="3"><span>Urinalysis</span></div> 
        <div><input type="checkbox" name="topic" value="4"><span>RPR/TPHA</span></div> 
        <div><input type="checkbox" name="topic" value="5"><span>Hepatitis B screening</span></div> 
        <div><input type="checkbox" name="topic" value="6"><span>Fasting Blood Sugar</span></div> 
        <div><input type="checkbox" name="topic" value="7"><span>Creatinine</span></div> 
        <div><input type="checkbox" name="topic" value="8"><span>Total Cholesterol(Low Cholesterol, High Cholesterol)</span></div> 
        <div><input type="checkbox" name="topic" value="9"><span>Triglyceride</span></div> 
        <div><input type="checkbox" name="topic" value="10"><span>VLDL</span></div> 
        <div><input type="checkbox" name="topic" value="11"><span>Blood Uric Acid</span></div> 
        <div><input type="checkbox" name="topic" value="12"><span>Anti-HAV Igm Screening</span></div> 
        <div><input type="checkbox" name="topic" value="13"><span>Anti HBaAg</span></div> 
        <div><input type="checkbox" name="topic" value="14"><span>Drug & Alcohol Test</span></div> 
        <div><input type="checkbox" name="topic" value="15"><span>Stool Culture</span></div> 
        </div 
        <?php } ?> > 
        <div class="col-xs-3"> 
        </div> 
       </div> 
       <div class="col-lg-6"> 
       </div> 
      </div> 
     </div> 
    </div> 
    <div class="col-lg-3"> 
    </div> 
</div> 

回答

0

問題是,當您的主複選框被設置時,PHP不會發送「隱藏的」HTML - 所以沒有內容被有條件地顯示。

你最好用CSS樣式display: hidden來隱藏你不想要的複選框,因爲HTML仍然會去瀏覽器(它不會被顯示)。然後,當用戶選中複選框時,可以使用javascript將CSS樣式更改爲display: initial,以便這些元素再次顯示。