I currently have a table with blank <td>s. Each time a <td> is clicked, it changes its background color.
I want to change the value of rcStatus button along with the colors.
Here's my current code:
HTML:
foreach( //conditionals ){
<td id="changeStatus">
<input type="button" name="rcStatus" id="rcStatus" value=""/>
</td>
}
javascript:
$('#table #td').click(
function(){
var cell = $(this),
state = cell.data('state') || 'first';
switch(state){
case 'first':
cell.addClass('red');
cell.data('state', 'second');
document.getElementById('rcStatus').value = "missed";
break;
// other cases here
}
});
The problem is, since my <td> is in a foreach statement, the input name is not unique.
So the only button value that changes onclick is the first button in the table.
Anyway I can fix this so that the button that changes is the one inside the <td> clicked?
Thanks!
foreachconditional? Is there akeyor avalueyou can append to yourinputidso you can get them accurately?