tags:

views:

17

answers:

1

i need the tr to change background color, text color and have a line through the txt.

To-Do Item Priority Due Date " value="checked" />
A: 

You have a much better chance of getting your question answered if you clean up the formatting, and ask a clear question. To clarify, do you want to dynamically set it to a predefined class that has the font attributes you're trying to set on it, or is it enough to change the item's "style" attribute to have these elements?

At the very least, your checkbox will need some javascript attached to it. This would be an example of the input generated for row 1 of the table--row 2 would have "t_row_2", etc. (all generated by PHP).

Put this script somwhere in a header:

<script type="text/javascript">
function setClass(chkbox,row_id){
  row = document.getElementById(rowid);
  if(row){
    if(elem.checked){
      row.setAttribute("class","checkedClassName");
    }else{
      row.setAttribute("class","uncheckedClassName");
    }
  }
}
</script>

This is what the input should would look like using this method:

<input type="checkbox" id="chk" onclick="setClass(this,'t_row_1)" />

If you're not afraid to play a little more with the javascript, and assuming your checkbox is within the tr in question, you can get rid of the row id parameter with a "getParentTr" function:

<script type="text/javascript">
function getParentTr(elem){
  parent = elem.parentNode;
  while(parent !== document.body){
    if(parent.type === "tr"){
      return parent;
    }
  }
  return null;
</script>

Then you would remove the second parameter from the "setClass" function above, and replace "row = document.getElementById(rowid);" with "row = getParentTr(elem);"

wilsona
i need to make it so that when the box is checked it changed the formatting of just that <tr> and the table is dynamic. thanks
supertech
what i need to do is change what class the <tr> is if thats possible
supertech
Well, the least-work way, since you're generating these, would be to have your trs set with sequentially-numbered-ids (if there's more than one table, you'll have to be sure to make them distinct if using this method), then have the onclick method call a function on the id of the tr that contains it. I'll edit my answer to show what I mean.Note that jQuery would make all of this easier, I'm just assuming you don't want to get into learning a new lib.
wilsona
does elem.checked need to be changed too? or it that what it should be kinda new to javascript
supertech
No, elem.checked doesn't need to be changed in JavaScript. Basically, the click will set the element, then trigger the onclick event, which will then evaluate based on the new value.
wilsona