echoing document.getElementById() with php variable as id - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Wednesday, June 15, 2022

echoing document.getElementById() with php variable as id

Hi I have a list of buttons with different id's like b_1, b_2, b_3 and so on. After that I have PHP code to interact with the database and get my results. Then I have created a variable that receives the identity of the rows that it finds in the table. I would like to use the result to change the background color of the different buttons. It works fine if I write the literal identity "b_1" or "b_2" and so on but not in the form of a variable ($trans_boton). I have tried in many ways and I can't find the key. Thanks for lighting.

$trans_boton = 'b_'.$data['numero'];

if($facta == $respuesta){
echo "<script>"; echo "document.getElementById('b_1').style.backgroundColor='red';"; echo "</script>";}


source https://stackoverflow.com/questions/72609778/echoing-document-getelementbyid-with-php-variable-as-id

No comments:

Post a Comment