2017-12-19 4 views
2

이용 약관에 모달이 적용되어 모달 외부에있는 숨겨진 입력 필드 값 (name = "agree")을 "no"에서 " 사용자가 수락 (Acepto) 버튼을 클릭하여 조건을 수락하면 "예"로 변경됩니다. 이유는 양식을 이용 약관에 동의하여 보낼 수 있기 때문입니다. 미리 감사드립니다. 숨겨진 필드의 값을 모달에서 변경하는 방법

은 (결코 변하지 않는다 "동의"입력 필드의 그것의 작동하지 않는 값) 내 코드입니다 :

<form id="formced" ... > 
.... 
<div class="form-group"> 
     <button type="button" class="btn btn-default" data-toggle="modal" data-target="#termsModal">Acepto los Términos y Condiciones </button> 
</div>        
<!-- Terms and conditions modal --> 
<div class="modal fade" id="termsModal" tabindex="-1" role="dialog" aria-labelledby="Términos y Condiciones" aria-hidden="true"> 
<div class="modal-dialog modal-lg"> 
    <div class="modal-content"> 
     <div class="modal-header"> 
      <h3 class="modal-title">Términos y Condiciones</h3> 
     </div> 
     <div class="modal-body"> 
     <p>TERMINOS Y CONDICIONES ...</p> 
     </div> 
     <div class="modal-footer"> 
      <button type="submit" class="btn btn-primary" id="agreeButton" data-dismiss="modal">Acepto</button> 
      <button type="button" class="btn btn-default" id="disagreeButton" data-dismiss="modal">No Acepto</button> 
     </div> 
    </div> 
</div> 

<input type="hidden" name="agree" value="no" /> 

<script> 
    $(document).ready(function() { 
    // Update the value of "agree" input when clicking the Agree/Disagree button 
    $('#agreeButton, #disagreeButton').on('click', function() { 
     var whichButton = $(this).attr('id'); 
     $('#formced') 
      .find('[name="agree"]') 
       .val(whichButton === 'agreeButton' ? 'si' : 'no') 
       .end() 
    }); 
}); 
</script>  

<a class="btn btn-primary btn-md" role="button" onClick="return ParaOtrosNavegadores1();">Continuar <span class="glyphicon glyphicon-forward" aria-hidden="true"></span></a> 
      <script type="text/javascript"> 
       function ParaOtrosNavegadores1(){ 
        document.formced.submit(); 
       } 
      </script> 
</form> 
+0

사용중인 부트 스트랩 버전은 무엇? 가능한 시작점은 모달을 닫는 "동의 함"버튼이있는 모달의 콜백 기능을 통해이를 수행 한 다음 닫을 때 확인란을 선택하는 것입니다. – Adam

+1

find ('[name = "agree"]')'할 수있다. '('[name = "agree"] ')'를'$ ('body')로 바꾼다. –

+2

코드에 숨겨진 필드가 표시되지 않습니다. 이것은 당신의 자바 스크립트를 확인하기가 어렵습니다. – daddygames

답변

0

Working fiddle.

처럼 직접 요소를 대상으로 시도 :

$('input[name="agree"]').val(assignedVal); 

코드 :

function ParaOtrosNavegadores1() { 
 
    document.formced.submit(); 
 
} 
 

 
$(document).ready(function() { 
 
    // Update the value of "agree" input when clicking the Agree/Disagree button 
 
    $('#agreeButton, #disagreeButton').on('click', function() { 
 
    var whichButton = $(this).attr('id'); 
 
    var assignedVal = whichButton === 'agreeButton' ? 'si' : 'no'; 
 

 
    $('input[name="agree"]').val(assignedVal); 
 

 
    console.log('Hidden field value is : ' + $('input[name="agree"]').val()); 
 
    }); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" /> 
 
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> 
 
<input type="hidden" name="agree" /> 
 

 
<form id="formced"> 
 
    <div class="form-group"> 
 
    <button type="button" class="btn btn-default" data-toggle="modal" data-target="#termsModal">Acepto los Términos y Condiciones </button> 
 
    </div> 
 
    <!-- Terms and conditions modal --> 
 
    <div class="modal fade" id="termsModal" tabindex="-1" role="dialog" aria-labelledby="Términos y Condiciones" aria-hidden="true"> 
 
    <div class="modal-dialog modal-lg"> 
 
     <div class="modal-content"> 
 
     <div class="modal-header"> 
 
      <h3 class="modal-title">Términos y Condiciones</h3> 
 
     </div> 
 
     <div class="modal-body"> 
 
      <p>TERMINOS Y CONDICIONES ...</p> 
 
     </div> 
 
     <div class="modal-footer"> 
 
      <button type="submit" class="btn btn-primary" id="agreeButton" data-dismiss="modal">Acepto</button> 
 
      <button type="button" class="btn btn-default" id="disagreeButton" data-dismiss="modal">No Acepto</button> 
 
     </div> 
 
     </div> 
 
    </div> 
 
    <a class="btn btn-primary btn-md" role="button" onClick="return ParaOtrosNavegadores1();">Continuar <span class="glyphicon glyphicon-forward" aria-hidden="true"></span></a> 
 
</form>

+1

고마워,이 해결되었습니다. 내 "js/jquery-1.11.3.min.js"에서 중계했지만 한 번 연결된 "ajax/libs/jquery/2.1.1/jquery.min.js"는 매력처럼 작동했습니다. –