2011-05-04 3 views
0

저는 시스템을 수정하는 임무를 수행하는 시점에 있으며 "iagree"스타일 체크 박스를 추가해야합니다. 입력란이 비어 있으면 양식이 제출되지 않습니다. 즉 제출하지 않으려면 경고가 필요합니다. 동의 함 확인란 또는 라디오 버튼이 선택되지 않은 경우 나는 백만 가지를 시도 했으니 까 누구든지 그것을 알아낼 수 있다면 너는 내 신이 될 것이다.동의 함 라디오 버튼 또는 확인란을 선택하십시오. 겉으로보기에는 불가능합니다

다음은 빈 필드를 검사하고 경고를 표시하는 자바 스크립트입니다. 이름에 "동의"하는 체크 라디오 버튼을 추가해야합니다.

<div class="internal_booking_form"> 
    <script type="text/JavaScript"> 
    <!-- 

코드 바로 아래에있는 기능은 내가 가지고있는 일련의 체크 박스와 라디오 버튼의 값을 계산합니다. 나는 이미 어떤 것을 가지고 있지만 그것이 내가 메모를 포함 할 것이라고 생각한다면 그것은 확실하지 않다.

$(document).ready(function() { 
      function recalculate() { 
     var sum = 0; 
     var base = 0; 

     $("input[type=checkbox]:checked").each(function() { 
      sum += parseInt($(this).attr("rel")); 
     }); 

     sum += parseInt($(":radio[name='duration']:checked").attr("rel"), 10); // or some attribute that has the price 
     $("#output").html(sum); 
    } 

     $("input[type=checkbox], :radio[name='duration']").change(function() { 
     recalculate(); 
    }); 

    }); 

내가 그것이 checkcheckbox 기능

  function newPopup(url) { 
       popupWindow = window.open(
      url,'popUpWindow','height=700,width=800,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes') 
      } 

    function checkForm() { 
     var err=0; 
     var msg2=""; 


    <?php 
    $reqFields=array(
     "name", 
     "phone", 
     "email", 
     "comments", 
     "suburb", 
     "postcode", 
     "captcha" 

    ); 

    foreach ($reqFields as $v) { ?> 

     if (document.getElementById('<?php echo $v?>').value==0 || document.getElementById('<?php echo $v?>').value=="00") { 
      if (err==0) { 
       document.getElementById('<?php echo $v?>').focus(); 
      } 
      document.getElementById('<?php echo $v?>').style.backgroundColor='#ffa5a5'; 
      err=1; 
     }<?php 




    } 
    ?> 

     var reg1 = /(@.*@)|(\.\.)|(@\.)|(\[email protected])|(^\.)/; // not valid 
     var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid 
     if (document.getElementById('email').value==0 || !reg2.test(document.getElementById('email').value)) { 
     if (err==0) { 
      document.getElementById('email').focus(); 
     } 
     document.getElementById('email').style.backgroundColor='#ffa5a5'; 
     err=1; 
     } 




    if (err==0) { 
       return true; 
     } else { 
      alert("Please complete all highlited fields to continue."); 
      return false; 
     } 

    } 

    function checkFieldBack(fieldObj) { 
     if (fieldObj.value!=0) { 
      fieldObj.style.backgroundColor='#EAEAEA'; 
     } 
    } 

    function checkNumeric(value){ 
      var anum=/(^\d+$)|(^\d+\.\d+$)/ 
      if (anum.test(value)) 
       return true; 
      return false; 
     } 


    function noAlpha(obj){ 
     reg = /[^0-9.,]/g; 
     obj.value = obj.value.replace(reg,""); 
    } 

    //--> 
    </script> 
    <form name="ff1" enctype="multipart/form-data" method="post" action="booking.event.processing.php" onsubmit="return checkForm();"> 

답변

0

나는 당신의 "iagree"체크 박스는 아이디 iagree을 가지고 가정을 배치하는 가장 좋은 것입니다 가정 코드의 나머지 부분입니다. 삽입 할 경우

if(!$('input#iagree').is(":checked")) { 
    err = 1; 
} 

if (err==0) { 
... 

이렇게하면됩니다. 동의하기위한 명시적인 정보를 원할 경우 추가 메시지 상자를 추가 할 수 있습니다.

+0

감사합니다. 지금 테스트 중입니다. – Simon

+0

예! 작동합니다. 고맙습니다! – Simon

관련 문제