2014-10-02 50 views
0
<table class="table table-bordered table-striped"> 
     <tr> 
      <th></th> 
      <th>Excellent</th> 
      <th>Satisfactory</th> 
      <th>Unsatisfactory</th> 
      <th>Poor</th> 
     </tr> 
     <tr> 
      <?php 
       $empty = false; 
       $x = 1 ; 
       while($x<=4) 
       { 
        if($Comments['Preparation']==$x) 
        { 
         $empty = true; 
        } 
        $x++; 
       } 
      ?> 
      <td><b>Preparation</b>- Applicant has prepared his/her himself for the interview and the necessary documents.</td> 
      <td><input type="radio" name="Preparation" value="4" <?php if($Comments['Preparation']=='4') {echo "checked='checked'";} else if($empty) {echo "disabled='disabled'";}?>></td> 
      <td><input type="radio" name="Preparation" value="3" <?php if($Comments['Preparation']=='3') {echo "checked='checked'";} else if($empty) {echo "disabled='disabled'";}?>></td> 
      <td><input type="radio" name="Preparation" value="2" <?php if($Comments['Preparation']=='2') {echo "checked='checked'";} else if($empty) {echo "disabled='disabled'";}?>></td> 
      <td><input type="radio" name="Preparation" value="1" <?php if($Comments['Preparation']=='1') {echo "checked='checked'";} else if($empty) {echo "disabled='disabled'";}?>></td> 
     </tr> 
     <tr> 
     </tr> 
     </table> 

我試圖預先選擇表格內的單選按鈕,因爲我想顯示它。 if聲明表示我是否回顯「已檢查」。我一直在桌子外面使用它,它工作正常。 是否可以在表中使用單選按鈕?單選按鈕檢查不在表格內工作

有什麼問題?

+0

'不工作'是一個很好的描述。實際發生了什麼?這與預期結果有什麼不同 – Steve 2014-10-02 14:20:07

+0

我的預期結果是當我回顯檢查單選按鈕將被檢查。發生了什麼是另一個單選按鈕被禁用,但沒有選擇應該選擇的單選按鈕 – Maxxxxxxxx 2014-10-02 14:22:22

+0

'checked =「checked」' – chaos505 2014-10-02 14:22:32

回答

1

取代回顯"checked=''""disabled=''",將其更改爲"checked='checked'""disabled='disabled'"。另外,什麼是$empty

+0

我已經完成了,仍然在我的瀏覽器中單選按鈕沒有被檢查。$ empty是一個布爾值,如果單選按鈕將被禁用 – Maxxxxxxxx 2014-10-02 14:29:05

+0

您可以發佈更多的代碼,以便我可以看到發生了什麼?添加checked =「checked」應該預先選擇一個單選按鈕。 – danmullen 2014-10-02 14:32:27

0
<?php if($Comments['Preparation']=='4') {echo "checked='checked'";} ?> 
2

而不是{echo "Checked=''";} else if($empty) {echo "Disabled=''";}

它應該只是 {echo "checked";} else if($empty) {echo "disabled";}

checked=checked等不是形式如何處理無線電是怎麼檢查的,它只是

<input type="radio" value="radio_value" checked name="radio_name"> 
             ^^^^^^^ 

,而不是

<input type="radio" value="radio_value" checked=checked name="radio_name"> 
             ^^^^^^^^^^^^^^^ 

這就是你現在正在做的事情。

同樣的事情disabled

<input type="radio" value="radio_value" disabled name="radio_name"> 
             ^^^^^^^^ 

或者你也可以設置預先定義的變量:

$disabled = 'disabled'; 

$checked = 'checked'; 

再去做動態

{echo $checked;} else if($empty) {echo $disabled;}


根據你編輯:

{echo "checked='checked'";} else if($empty) {echo "disabled='disabled'";}

改變它

{echo "checked";} else if($empty) {echo "disabled";}

或如上面概述和使用可以隨時改變的變量。

+0

它現在有效。謝謝。 – Maxxxxxxxx 2014-10-02 14:53:40

+1

@Maxxxxxxxx不客氣。勾選我的答案旁邊的複選標記以標記已解決。以下是** http://meta.stackexchange.com/a/5235/**以防萬一,然後回到我的答案。乾杯 - 這是如何在Stack上完成的。 – 2014-10-02 14:56:08

0
<td><input type="radio" name="Preparation" value="4" <?php if($Comments['Preparation']=='4') {echo "checked";} else if($empty) {echo "disabled";}?>></td> 
      <td><input type="radio" name="Preparation" value="3" <?php if($Comments['Preparation']=='3') {echo "checked";} else if($empty) {echo "disabled";}?>></td> 
      <td><input type="radio" name="Preparation" value="2" <?php if($Comments['Preparation']=='2') {echo "checked";} else if($empty) {echo "disabled";}?>></td> 
      <td><input type="radio" name="Preparation" value="1" <?php if($Comments['Preparation']=='1') {echo "checked";} else if($empty) {echo "disabled";}?>></td> 

謝謝你們幫助我。我已經解決了這個問題。

+0

這不是Stack上的事情。 [''讀我的評論給你'](http://stackoverflow.com/questions/26162843/radio-button-checked-not-working-inside-a-table#comment41017312_26163343)在我的答案。 – 2014-10-02 15:03:10