Fixes php css

0

I have the following cards (cards) which are arrays with information inside, below it brings me many more arrays but now I want that when I press the state that is in the select it brings me by the state that I select Ejquee aprej trujillo they show me everything trujillo ... I tried javascript with clik event but at the time of appears only shows things like text (the css does not show and if I include css simply does not show)

THIS IS PART OF THE CODE ... the part of the card are simply another array

<?php
$stads= array("MIRANDA", "AMAZONA", "ANZOATEGUI"," APURE"," ARAGUA"," BARINAS"," CARABOBO"," COJEDES"," DELTA AMACURO"," DISTRITO CAPITAL"," CARACAS"," FALCON"," LARA"," MERIDA"," MONAGAS"," NUEVA ESPARTA"," PORTUGUESA","SUCRE","TACHIRA"," TRUJILLO"," VARGAS"," YARACUY"," ZULIA ");
$arrlength= count($stads);
echo "
<div class='col-md-3'>
    <div class='form-group'>
        <label for='cuadro1'>Estados:</label>
            <select class='form-control' id='cuadro1'>
";

echo "<option value='' id='cuadro2'></option>";
for ($x=0; $x < $arrlength ; $x++) { 
 if ($stads [$x]!=null ) {
    $cc= $stads[$x];

echo "<option value='$cc' id='cuadro2'>$cc</option>";
    }
}
echo " </select>
    </div>
</div>";
?>

     <br>
     <br>
     <hr>
<script>
document.getElementById("cuadro1").addEventListener("click", myFunction);

function myFunction() {
    document.getElementById("cuadro3").innerHTML = "<?php echo"(ACA NO PUEDO INCLUIR CSS )"  ?>";
}
</script>

<div id="cuadro3"></div>
    
asked by Daniel Martinez 18.07.2018 в 15:52
source

1 answer

2

I see several things that you are doing wrong in your code.

The event to register a change of select is change and not click:

document.getElementById("cuadro1").addEventListener("change", myFunction);

I do not understand what you are trying to say with "ACA I CAN NOT INCLUDE CSS".

You can enter the css directly in the html code with the style attribute for example:

document.getElementById("cuadro3").innerHTML = "<?php echo"<span style=\"color:red;\">Hola</span>"  ?>";

Or if you wish, you can write your css in the current file, when displaying your html code with javascript the styles will be automatically applied:

<script>
...............

    document.getElementById("cuadro3").innerHTML = "<?php echo"<span class=\"estilo1\">Hola</span>"  ?>";
.................
</script>
<style>
.estilo1 {
    color:red;
}
</style>

Neither do I understand why you use the PHP statement within the JAVASCRIPT variable. Explain why you are doing it to help you.

Greetings

    
answered by 18.07.2018 / 16:35
source