Otóż muszę zaznaczyć pewien checkbox, tylko nie bardzo wiem jak.
Moje checkboxy wglądają tak:
No i tu sedno sprawy. Jak (w JS) kliknięciem w link id="zaznacz", zaznaczyć np checkbox nr 6?
Pozdrawiam.
$('#zaznacz').on('click',function(e){ e.preventDefault(); $('input[type="checkbox"]:nth-child(3)').attr('checked','checked'); });
$('#zaznacz').on('click',function(e){ e.preventDefault(); $('input[type="checkbox"][value="6"]').attr('checked','checked'); });
$(window).load(function(){ $('#zaznacz1').on('click',function(e){ e.preventDefault(); $('input[type="checkbox"][value="4"]').attr('checked',true); $('input[type="checkbox"][value="5"]').removeAttr('checked'); $('input[type="checkbox"][value="6"]').removeAttr('checked'); }); $('#zaznacz2').on('click',function(e){ e.preventDefault(); $('input[type="checkbox"][value="4"]').removeAttr('checked'); $('input[type="checkbox"][value="5"]').attr('checked','checked'); $('input[type="checkbox"][value="6"]').removeAttr('checked'); }); $('#zaznacz3').on('click',function(e){ e.preventDefault(); $('input[type="checkbox"][value="4"]').removeAttr('checked'); $('input[type="checkbox"][value="5"]').removeAttr('checked'); $('input[type="checkbox"][value="6"]').attr('checked','checked'); }); });
$('#zaznacz').click(function(){ var twojaWartosc = 6; $('input[value="'+twojaWartosc+'"').attr('checked', true); });
$('.zaznacz').click(function(){ var twojaWartosc = $(this).attr('zaznacz'); $('input[value="'+twojaWartosc+'"][name="nazwa[]"]').attr('checked', true); });
$('input[type="checkbox"]').attr('checked', false);
$('.zaznacz').click(function(){ $('input[type="checkbox"]').attr('checked', false); var twojaWartosc = $(this).attr('zaznacz'); $('input[value="'+twojaWartosc+'"][name="nazwa[]"]').attr('checked', true); });
attr('checked', false);
prop('checked', false);
$('.zaznacz').click(function(){ $('input[type="checkbox"]').prop('checked', false); var twojaWartosc = $(this).attr('zaznacz'); $('input[value="'+twojaWartosc+'"][name="nazwa[]"]').prop('checked', true); });