Question

I'm after a script where one checkbox will uncheck another. It is a bit complicated though as all the data is loaded programatically. So if a checkbox is unchecked the procedure is to take its src value, then go through the other inputs and find inputs that have a title of 'RQlevel' + the src value of the clicked elements and set it to unchecked.

Here is the current code.

function levels() {
  var test = $(this).attr('src'); 
  if ($(this).is(':not(:checked)')) { 
    $(':input').each(function() { 
      if ($(this).attr('title') === ('RQLevel' + test)) {
        $(this).removeAttr('checked');
      }
    });
  }
}

There is a working example here that will illustrate the issue http://jsfiddle.net/V8FeW/7/ If both boxes are checked and the first box is then unchecked it should take the second box with it.

Marvellous

Was it helpful?

Solution

function levels() {
  var test = $(this).attr('src'); 
  if (!this.checked)
     $('input:checkbox[title=RQlevel' + test + ']').removeAttr('checked');
}

$(function() {
    $('input:checkbox').bind('change', levels);
});

Demo: http://jsfiddle.net/V8FeW/12/

OTHER TIPS

$('input [title="RQlevel"]').attr('checked', $(this).attr('checked'));

Here you can find a nice, short and elegant solution: http://briancray.com/2009/08/06/check-all-jquery-javascript/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top