I'm using a database in order to paint table cells with an specific color depending on a variable. If it is 1 is grey, if it is 0 is green. However, I'd like to make it so the grey ones can't change color with a click, while making it so the green ones change color when clicked. the 1s and 0s in the database can change at anytime if the value is changed. I can't make it so you can change the green cells with a click while keeping the grey onces from being changed.
I use this portion to check the database and color as intended:
$(document).ready(function(){
$("#pedido").click(function(){
var tipo = "TraD";
$.post("Controlador.php",{Tip:tipo}, function(datos){
json = JSON.parse(datos);
var Hor = json.Horario;
var tick = [], tock;
var hashes = Hor.split(',');
for(var i = 0; i < hashes.length; i++){
tock = hashes[i].split('=');
tick.push(tock[0]);
tick[tock[0]] = tock[1];
}
var Secuencia= "";
for(var i=2; i <= 55 ; i++){
if(tick[i]==1){
document.getElementById("d"+(i-1)).style.backgroundColor ="rgb(119, 136, 155)";
document.getElementById("d"+(i-1)).unbind('click');
}
}
As you can see, I was trying to disable the click option in the grey ones, but it isn't working at all. the table cells and how they change colors can be seen below:
<td style = "background-color: rgb(0, 250, 154); " onclick = "cambiar(this);" id = "d1"></td>
<td style = "background-color: rgb(0, 250, 154); " onclick = "cambiar(this);" id = "d2"></td>
<td style = "background-color: rgb(0, 250, 154); " onclick = "cambiar(this);" id = "d3"></td>
<td style = "background-color: rgb(0, 250, 154); " onclick = "cambiar(this);" id = "d4"></td>
<td style = "background-color: rgb(0, 250, 154); " onclick = "cambiar(this);" id = "d5"></td>
<td style = "background-color: rgb(0, 250, 154); " onclick = "cambiar(this);" id = "d6"></td>
If there is another way to solve this problem, I'm all ears. Thank you very much.
Edit: Alright, here is the function cambiar:
function cambiar(celda){
if( celda.style.backgroundColor == "rgb(0, 250, 154)"){
celda.style.backgroundColor="rgb(119, 136, 155)";
}else{
celda.style.backgroundColor="rgb(0, 250, 154)"; //778899
}
}