EDITO: The problem was that the query to the database was taking me the information of another user, not the one who had logged in. Absurd error, I have solved by doing a separate query knowing that this variable is only used for the script of changing colors.
Good morning,
I am running into a problem in javascript when I want to modify the CSS properties in fonts of some values indicated by the user, and I do not find any sense in what it does. By default I already have some CSS properties applied, but those properties can be modified, and depending on these new colors, I want to change the web design (colors).
There are elements that appear more than once, in different sections, but in theory to execute the same command should do the same, but I have found a case that does not.
The script is as follows:
<script type="text/javascript">
var color_fuerte = "#<?php echo $user['color_principal'] ?>";
var color_medio = "#<?php echo $user['color_secundario'] ?>";
var color_suave = "#<?php echo $user['color_fondo'] ?>";
var botones = document.getElementsByClassName("crear_hilo").length
if (botones > 0) {
var array_botones = new Array('crear_hilo', 'fa-search');
for (var i = 0; i < array_botones.length; i++) {
var d = document.getElementsByClassName(array_botones[i]).length;
for (var j=0; j<d; j++) {
document.getElementsByClassName(array_botones[i])[j].style.background = color_medio;
}
}
}
</script>
It does not have much intrigue, first I check if the element with var botones = document.getElementsByClassName("crear_hilo").length
exists, if it gives me a length it means that the element exists, then it is when I make the changes. As there are things that imply others, that is, whenever I have the button with the class "create_hilo" I always have a search engine icon, so I include an array to go through these elements individually and modify their properties.
The fact is that I have the class "create_hilo" twice, in different sections, and curiously in the first YES that it works, and in the second it does NOT work for me, it changes the style, but to the one that already has by default, thing that I do not see neither feet nor head ... If for example instead of the variable valor_medio
directly use its value, ie document.getElementsByClassName(array_botones[i])[j].style.background = "rgb(194, 104, 104)";
, the 2 classes are changed, but obviously I can not do that because I want it to be modify according to the color chosen by the user. In the console it does not give me any error, but I do not understand where the problem is.
I also leave the part of the HTML code:
echo "<div class='creacion_hilo'>";
if (isset($_SESSION['usuario'])) {
echo "<a class='crear_hilo' href='crear_hilo.php?foro=" . str_replace(" ", "%",$foro) . "&subforo=" . $subforo ."'>+ CREAR HILO</a>";
} else {
echo "<p class='crear_hilo no_sesion'>+ CREAR HILO</p>";
}
echo "<div class='busqueda_hilo'>";
echo "<input type='text' name='search_hilo' placeholder='Buscar en este foro...'>";
echo "<label class='fa fa-search' for='search_hilo'></label>";
echo "</div>";
echo "</div>";