2016-09-05 36 views
-1

在我的頁面中,有3個級別的下拉選擇框,子級隱藏,直到選擇父級。文本框在上級父級更改後不會消失

水平
健康測試組織(級別1) - >測試類型(級別2) - >測試結果(級別3)

在一個路線的終點,兩個盒子(LDI和RDI)除了第3級的測試結果之外還會出現。雖然箱子當我改變3級消失,如果我改變那些不消失,1級或2

這裏是我的問題的屏幕截圖,
沒有選擇,
No selection
1級選擇,
Level 1 selected
級別選擇2,
Level 2 selected
上述3級選擇框出現,
Level 3 selected
而且問題,
Problem
我只是改變健康測試組織(1級),並在這兩個盒子(LDI和RDI)仍然存在。

順便說一句,這裏是PHP腳本中編碼的那部分的JavaScript;

function options($type) 
{ 
    if($type== 'org') 
    { 
     return array('Not selected'=>'','OFA'=>'ofa','CERF'=>'cerf','CHIC'=>'chic','AHT'=>'aht','PennHip'=>'pennhip','Other'=>'other'); 
    } 
    if($type== 'pass') 
    { 
     return array('Not selected'=>'','PASS'=>'1','FAIL'=>'0'); 
    } 
    if($type== 'type') 
    { 
     return array('Not selected'=>'', 
     'Eye (CERF)' => 'eye', 
     'Cardiac (OFA)' => 'cardiac', 
     'Elbow (OFA)' => 'elbow', 
     'Hips (OFA)' => 'hips', 
     'Patellar Luxation (OFA)' => 'pl', 
     'Thyroid (OFA)' => 'thyroid', 
     'DNA (OFA)' => 'dna', 
     'Primary Open Angle Glaucoma (OFA)' => 'poag', 
     'Other (not active yet)' => 'other', 
     'Longevity (not active yet)' => 'longevity', 
     'Genotype (not active yet)' => 'genotype', 
     ); 
    } 
    if($type== 'result') 
    { 

    } 
} 

function get_for_dog($id) 
{ 
    $arr[':id'] = $id; 
    $str = 'SELECT * FROM ' . $this->table . ' WHERE dog=:id'; 
    if ($this->obj_debug == 1 || $this->core_debug == 1) 
     echo "$str<br>"; 
    return $this->run_query($str,$arr); 
} 

function resultdd($test,$result) 
{ 
     $list = array(); 
     foreach($this->testresults as $txt => $val) 
     { 
      if(strstr($val,$test.'.') ||$val =='') 
      { 
       $list[$txt] = $val; 
      } 
     } 
     if(sizeof($list) > 0 && $test != '') 
     { 
      $buf = '<select name="rating">'; 
      foreach($list as $txt =>$val) 
      { 
       $buf .= '<option value="'.$val.'" '; 
       if($val == $result) 
        $buf .= ' selected '; 
       $buf .= '>'.$txt.'</option> 
       '; 
      } 
      $buf .= '</select>'; 
     } 
    return $buf; 
} 

function customFields($i=0,$r='') 
{ 
    $buf = ''; 
    if($this->data[$i]['rating'] =='pennhip.ldirdi' || $r =='pennhip.ldirdi') 
    { 
     $dft = array('ldi'=>'','rdi'=>''); 
     if($this->data[$i]['rating_data'] != '') 
     { 
      $dat = json_decode($this->data[$i]['rating_data'],true); 
      if(sizeof($dat) == 2) 
       $dat=$dat; 
      else 
       $dat = $dft; 
     } 
     else 
      $dat = $dft;  
     $buf .= 'LDI <input type="text" name="rating_data[]" value="'.$dat['ldi'].'" /><br><br>'; 
     $buf .= ' <input type="hidden" name="rating_key[]" value="ldi" />'; 
     $buf .= 'RDI <input type="text" name="rating_data[]" value="'.$dat['rdi'].'" /><br><br>'; 
     $buf .= ' <input type="hidden" name="rating_key[]" value="rdi" />'; 
    } 
    return $buf; 
} 

我確信有辦法擺脫這些箱子,我會很感激任何幫助。

回答

0

這實際上看起來很混亂,但是你在做什麼來使LDI/RDI首先顯示?

從一目瞭然的最簡單的解決方案是,當您更改測試類型時,只需將輸入的樣式更改爲display: none,這可以通過onchange()完成。

+0

正在做的事情是如果「測試結果」已選擇爲「LDI/RDI - PennHip」,這些箱子被添加到與該頁面我在問題中顯示的代碼。而且,我沒有在這個網站上創建這個框架或任何代碼,我只是添加了一些功能並糾正了像這樣的som內容。不幸的是,我足夠了解JavaScript,HTML或PHP來理解你的建議。你能解釋一下如何做這些改變嗎? –

+0

這4行對網頁的整體設計幫助不大。我們需要看看點擊「測試類型」時會發生什麼。嘗試找到與'測試類型'選擇框相關的代碼,以便我們可以看到'onchange'期間發生了什麼。此外,這是否使用jQuery? –

+0

我更新了代碼來解釋清楚PHP的功能。我希望它有幫助。而且,是的,它使用jquery。 –

0

我發現在JavaScript中控制級別2 & 3的函數在運行時沒有將該標記(cfs)設置爲空。所以,爲了解決這個問題,我在這些函數中添加了行,以便在每次運行時將該標記設置爲空。

下面是代碼,我增加了線條,

function popResults() 
{ 
    $("#cfs").html(""); // <-- added this line 
    var t = ''; 
    if($("select[name='type'] option:selected").val().length >0) 
     t = $("select[name='type'] option:selected").val(); 
    else 
     t =$("#testtypes").attr("data-type"); 

    $.ajax({url: "ajax_results.php?test="+t+"&result=" + $("#testresults").attr("data-result"), success: function(result){  
     $("#testresults").html(result); 
     $("select[name='rating']").change(function() { 
      $.ajax({url: "ajax_customFields.php?r="+$("select[name='rating'] option:selected").val(), success: function(result){ 
       $("#cfs").html(result); // <-- already there 
      }}); 
     });   
    }}); 
} 

function popTypes() 
{ 
    $("#cfs").html(""); // <-- added this line 
    $.ajax({url: "ajax_types.php?org="+$("select[name='org'] option:selected").val()+"&type=" + $("#testtypes").attr("data-type"), success: function(result){ 
     $("#testresults").html(''); 
     $("#testtypes").html(result); 
     $("select[name='type']").val(''); 
     $("select[name='type']").change(function() { 
      popResults(); 
     });  
    }}); 
}