2014-01-28 4 views
0

나는 다음과 같은 형식이 있습니다jQuery를이 : 라디오 버튼을 선택하면 확인할 수 없습니다

<div class="form-radios"> 

    <!-- OPTION #1 --> 

    <div class="form-item form-type-radio">    
     <input type="radio" name="auswahl_radio" id="option1" class="form-radio"> <label class="option" for="option1">Option 1</label> 

     <div class="radio-supplement"> 
      <p>Please accept:</p> 
      <input type="checkbox" id="checkbox_1" value="beer"><a href="#">Checkbox 1</a> 
      <input type="checkbox" id="checkbox_2" value="wine"><a href="#">Checkbox 2</a> 
     </div>  

    </div> 


    <!-- OPTION #2 --> 

    <div class="form-item form-type-radio"> 
     <input type="radio" name="auswahl_radio" id="option2" class="form-radio"> <label class="option" for="option2">Option 2 </label> 
    </div> 


    <!-- OPTION #3 --> 

    <div class="form-item form-type-radio"> 
     <input type="radio" name="auswahl_radio" id="option3" class="form-radio"> <label class="option" for="option3">Option 3</label> 
    </div> 

    </div> 

내가 달성하고자하는 것은을 사용자가 옵션 # 1을 제출 버튼을 클릭하고 확인, 다음 내 스크립트입니다 div.radio-supplement에있는 두 개의 체크 박스가 모두 선택되어 있는지 확인해야합니다. 적어도 하나 이상을 선택하지 않으면 양식을 보내면 안됩니다. 여기

내가 생각 해낸 관련 jQuery를 스크립트입니다하지만 작동하지 않습니다

var checkbox_1 = $('#checkbox_1').prop('checked'); 
var checkbox_2 = $('#checkbox_2').prop('checked'); 

    if ($("#option1").is(':checked')) { 

     if ((checkbox_1 == true) && (checkbox_2 == true)) { 
       return true; 
      } else { 
       $('.messages_error').html('At option1 please check both checkboxes'); 
       window.scrollTo(0,0); 
       return false; 
     }; 

    }; 

당신의 사람이 오류를 볼 수 있습니까? 이와

+0

'onclick' 이벤트 (또는 jquery'click')를 사용하여 스크립트를 트리거합니까? – Thundar

+0

jquery가있는 @Thundar $ ('# button'). on ('click', function() {...}); – MaxNagler

답변

0

시도 :

var radios = jQuery("input[name='auswahl_radio']"); 
var radio_is_checked = radios.filter(":checked") ; 

다음이 검사는 변수를 radio_is_checked.

+0

여전히 작동하지 않습니다. – MaxNagler

+0

여기를 참조하십시오. http://jsfiddle.net/ndHN3/ – Riad

관련 문제