0

I'm actually trying to make something like a pokedex for forza horizon 5, you checked the box when you unlock everything on the car. But i have a problem when i need to use the local storage who are there. I can see them "true" in the inspector but i try a lot of thing but nothing work.

If someone has a solution for me

Thanks

My php doc to create the 500 div of cars

<?php 
include('data.php'); 
$data = getCars();
$pagetitle = 'Equipe est OK';
include('javascript.js'); 
?>

    <html>
        <?php include('head.php'); ?>
        <body>
              <!--  <?php foreach($data as $value){ ?>
                    <li><?php echo $value["1"] . ' (' . $value["text"] . ')'; ?></li>
                <?php } ?> -->
            <section class="content">
                
                <div class="content__dispo">
                    <?php foreach($data as $value){ ?>
                        <div class="block_car">
                            <span><?php echo $value["text"] ?></span>
                            <input class="input" type="checkbox">
                        </div>
                    <?php } ?> -->
                </div>
    
            </section>
        </body>
    </html>

and my javascript to select them and to put on them an addeventlistener for my localstorage :

var input = document.getElementsByClassName('input');
let con = 0;
for (let i = 0; i < input.length; i++) {

    input[i].addEventListener("click", (e) => {
        if(input[i] == true){
            localStorage.setItem("input"+[i], input[i].unchecked);
        } else {
            localStorage.setItem("input"+[i], input[i].checked);
        }
    });

}

console.log(input);
  • Won't fix your problem, but you should use triple equals here, read more: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality – Peter Toth Nov 29 '21 at 22:14
  • There is no `unchecked` property – epascarello Nov 29 '21 at 22:51
  • `"input"+[i]` what is that supposed to be? `input1`? I assume you just want `input + i` – epascarello Nov 29 '21 at 22:52
  • If this is a Javascript problem, PHP is not helpful (the reverse is also true.) Edit your question to include only relevant tags and code. – miken32 Nov 29 '21 at 22:58
  • And `i` inside the event handler callback likely isn't what you think it was either, see https://stackoverflow.com/questions/750486/javascript-closure-inside-loops-simple-practical-example – CBroe Nov 30 '21 at 08:16

0 Answers0