1๐
โ
$("#delete").click(function() {
if ($('input[type="checkbox"]:checked').length > 0) {
alert("Checked");
} else {
alert("Not checked");
}
});
If you have other checkboxes on page then add a class
to your <input>
and select items in JS by this class:
<input type="checkbox" class="deletechk" name="selectedvalues[]"
value="{{ result.object.user_id }}">
And in Javascript code:
if ($('.deletechk:checked').length > 0) {
...
}
๐คcatavaran
0๐
You need to change your Javascript to below and instead of alerts can set a flag and break loop by returning false if they have checked a checkbox (see this Fiddle):
$("#delete").click(function(){
var checkboxes = $('input[type="checkbox"]');
$(checkboxes).each(function(index) {
if($(this).is(':checked')) {
alert('checked');
} else {
alert('You must select at lease one user');
}
});
});
๐คZaki
- [Answer]-Accessing a full object through a relation in Django
- [Answer]-Whether to (and how to) handle multiple many-to-many relationship through a common intermediary/join table in django?
- [Answer]-How to get actual value from HttpResponse in view?
- [Answer]-Django queryset aggregate multiple operations fields
0๐
In HTML add :
<input type="checkbox" id="{{result.object.user_id}}"
name="selectedvalues[]" value="{{ result.object.user_id }} class="mybox">
jquery:
$( "#delete" ).click(function(e) {
var checks=( $(".mybox").val());
if(!checks)
{
alert('You must select at lease one user');
e.PreventDefault()
{
});
๐คblaz1988
- [Answer]-Django- Using Parameters To Display Entry
- [Answer]-Can we depend on Django not verifying field length?
- [Answer]-Python social auth linkedin picture url is null
Source:stackexchange.com