2013-11-19 2 views
0

Я хочу показать предупреждение, если флажок не установлен. это мой кодAlert on chekbox button not selected

<label class="checkbox"><input type="checkbox" name="kopi[]" value="Kopi-1>1</label> 
<label class="checkbox"><input type="checkbox" name="kopi[]" value="Kopi-2>2</label> 
<label class="checkbox"><input type="checkbox" name="kopi[]" value="Kopi-3">3</label> 
<input type="submit" name="submit" value="" class="btn next"> 
<script type="text/javascript"> 
    $(document).ready(function(){ 
     var $checkbox = $('input:checkbox[name="kopi"]'); 
     $checkbox.change(function() { 
      var $selected = $radios.filter(':notchecked'); 
       alert('no.3 not checked, direct to thank you page!'); 
       window.location="thank-you.php"; 
     }); 
    }); 
</script> 
+1

'(': нет (: проверено)')' ' – UDB

+0

$ radios.filter (': notchecked'); 'что такое' $ radios' здесь? – Jai

ответ

0

попробуйте следующий код:

<label class="checkbox"><input type="checkbox" name="kopi[]" value="Kopi-1>1</label><label class="checkbox"><input type="checkbox" name="kopi[]" value="Kopi-2>2</label><label class="checkbox"><input type="checkbox" name="kopi[]" value="Kopi-3">3</label><input type="submit" name="submit" value="" class="btn next"><script type="text/javascript"> 
$(document).ready(function(){ 
    var $checkbox = $('input:checkbox[name="kopi"]'); 
    $checkbox.change(function() { 
     var $selected = $radios.filter(':not(:checked)'); 
      alert('no.3 not checked, direct to thank you page!'); 
      window.location="thank-you.php"; 
    }); 
}); 

Заменить "var $selected = $radios.filter(':notchecked');" с

var $selected = $radios.filter(':not(:checked)'); 

что все

0

Попробуйте как

$checkbox.change(function() { 
    if(!$(this).prop('checked')) { 
     var $selected = $radios.filter(':notchecked'); 
     alert('no.3 not checked, direct to thank you page!'); 
     window.location="thank-you.php"; 
    } 
}); 
+0

спасибо за помощь, он работает – user2977789

1

попробовать что-то вроде этого

 $(document).ready(function(){ 
      var $checkbox = $('input:checkbox[name="kopi"]'); 
      $checkbox.change(function() { 
       if(this.checked){ 
        // your code goes here 
       } 
      }); 
     }); 
0

Вы можете попробовать это:

$(document).ready(function(){ 
    var $checkbox = $('input:checkbox[name^="kopi"]'); 
    $checkbox.change(function() { 
     ($(':checked').length < $checkbox.length) ? alert('no.3 not checked, direct to thank you page!') : window.location="thank-you.php";  
    }); 
});