2014-09-17 2 views
0
<?php foreach ($types_show as $size): ?> 
    <td class='size_rdo'><?php echo Form::radio('radio_size', $value)?></td> 
<?php endforeach;?> 

일부 라디오 버튼이 표시되며 $value을 PHP로 보내려고합니다. DB에 값이 있으면 라디오 버튼을 사용할 수 있고, 그렇지 않으면 비활성화로 설정할 수 있습니다.DB 쿼리 결과에 따라 라디오 버튼을 비활성화하는 방법은 무엇입니까?

답장을 보내 주셔서 감사합니다.

$(':radio[name=radio_size]').each(function(){ 
     $.ajax({ 
      type: "GET", 
      url: "/management/order/get_size", 
      data: {radio_size:radio_size}, 
      cache: false, 
      dataType: 'json', 
      success: function(data) { 
       if (data) { 
       $(this).attr("disabled",true); 
      } 
      }, 
     }); 
    }); 
+0

사용중인 프레임 워크 자바 스크립트를 필요가 없다? – Fractaliste

+0

그것은 연료입니다 .... – shine

답변

0

나는 FuelPhp 당신이 할 수 있다고 생각 Form 헬퍼에 속성을 추가하는 PHP에서 (이 프레임 워크를 알지 못하지만, 제가 알고있는 또 다른 프레임 워크, see the documentation처럼 작동하는 것 같습니다).

<?php foreach ($types_show as $size): ?> 
    <td class='size_rdo'> 
     <?php if($value) // Here I don't understand what you want to test on your 
         // condition, you must correct it depending of your needs 
      // If the value is not good, then add the disabled attribut 
      echo Form::radio('radio_size', $value, array('disabled'))?> 
     else // If the value is the good one, just continue like you did 
      echo Form::radio('radio_size', $value)?> 
    </td> 
<?php endforeach;?> 

은 그럼 당신은

0

모든 라디오 버튼에 대해 실제로 ajax 호출을 원하면 확실하지 않습니다. 어쨌든 ...

을 하나의 호출을 수행 한 후 루프를 모든 라디오를 확인하기 위해 더 나은 것, 당신은 $를 통과해야 (이)

$(':radio[name=radio_size]').each(function(){ 
    var $this = $(this); 
     $.ajax({ 
      type: "GET", 
      url: "/management/order/get_size", 
      data: {radio_size:radio_size}, 
      cache: false, 
      dataType: 'json', 
      success: function(data) { 
       if (data) { 
       $this.attr("disabled",true); 
      } 
      }, 
     }); 
    }); 
+0

한 통화하는 방법? 코드를 작성할 수 있습니까? – shine