2011-05-04 28 views
0

我在修改系統的任務的最後一點,我需要添加一個「iagree」樣式複選框。如果字段爲空,系統就不會提交表單,但是我需要它不提交,即彈出警告。當我同意複選框或單選按鈕沒有被選中。我已經嘗試了一百萬件事情,所以如果任何人都能弄明白,你將成爲我的上帝。添加一個我同意單選按鈕或複選框。看似不可能

以下是我的JavaScript檢查空白字段等,並顯示警告。我需要添加名爲「同意」的單選按鈕。

<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 2011-05-04 08:01:16

+0

是的,它的工作原理!謝謝! – Simon 2011-05-04 08:08:28

相關問題