3

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

1

3 Answers 3

3
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/

Sign up to request clarification or add additional context in comments.

1 Comment

One more thing. How to add the attribute disabled as well. $('input:checkbox[title=RQlevel' + test + ']').Attr('disabled','disabled'); does not work
1

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

1 Comment

Thanks but that won't do it as we do not know the id of the other checkbox as they are generated programatically and there may be multiple checkboxes with that title RQlevel that would also have to be unchecked, again not known until the page is generated.
0

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

1 Comment

Thanks but that won't do it either as we are looking for all checkboxes with the same title. We don't know how many their will be and cannot place them in the same fieldset as they are generated programatically based on the clients entries into a form.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.