Setting a checkbox to "checked"

Setting a checkbox to "checked"

martinadamsmartinadams Posts: 2Questions: 0Answers: 0
edited September 2010 in General
Allan, what an amazing technology you created. I'm impressed and wish you best of luck with it. I'll donate as soon as I'm ready to launch.

I'm trying to set a checkbox to "checked" once another checkbox in the same row has been set to "checked" as well. Here's the code:

[code]

$('input').bind('click', function () {
oTable.fnSort( [ [1,'asc'], [2,'desc'], [5,'desc'], [3,'desc'], [4,'desc'], [6,'asc'], [7,'desc'] ] );
var thisrow = $(this).closest("tr").get(0);
var aRow = oTable.fnGetPosition(thisrow);
var aData = oTable.fnGetData( aRow );
if (aData[3] == 1) {
aData[4].attr('checked', true);
}
});
[/code]

The .attr() function doesn't seem to work. I scoured the entire forum, but couldn't find a way to make this work.

Any ideas?

Thanks much,

Martin

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi Martin,

    That data array from fnGetData is just an array of strings, not the TD (or more importantly in this case INPUT) elements. So what I think you'll need to do is something like $('input', this.parentNode.parentNode).attr('checked', true); . This will get all input elements (you might need to refine it) of the parentNode's (TD) parentNode (TR) (again if you have your checkboxes buried down deeper, it's probably worth using the jQuery parent() or find() methods).

    Hope this helps.

    Allan
  • martinadamsmartinadams Posts: 2Questions: 0Answers: 0
    Thanks much, Allan. This worked like gold.

    Martin
This discussion has been closed.