4
Good morning to you all! Gentlemen, I have a table where I upload information from the database, and I display it in this table. The table is already ready and loading the data right. What I need is to change the backgroud color of one of these cells by taking into account a condition, which is the following: If the information I have is equal to’S' it will change the text to 'Hit' and backgroud to blue for example, if it is not the same, change the text to 'Error' and backgroud to redness.
I’ve tried to do it this way:
function status(){
var status = document.getElementById("idcampostatus").value;
if(status == "S"){
//status.value = "Acerto";
status.style.backgroundColor="#428bca"
}else{
//status = "Erro";
status.style.backgroundColor="#d9534f";
}
}
But I don’t know if this function is really right, nor how to call in the table_(cell)_, because it’s not a clickable element, and I don’t know if the onLoand()
works on a table.
From now on I thank everyone for their help!
@Rafael Acioly think that removing the tag
PHP
it’s not right, I put it back together.– Sergio
@Sergio José’s doubt relates to CSS training using JS, as he said at the beginning of the post
"A tabela já está pronta e carregando os dados direitinho."
there is no doubt regarding PHP in this post.– RFL
@Rafaelacioly but if it mounts this in PHP, to add a class to a static element is better to do this in PHP than in Javascript. Apart from that he himself joined the tag.
– Sergio
Clarifying, I put the php tag just to let you know that the project is being done in php. If by chance, the best solution is in php, I will use it because it is already working with php.
– José Allison