javascripthtmlerror-handlingsyntax-errorlocation-href

unexpected end of input in html?


my code keeps giving me this error "Uncaught SyntaxError: Unexpected end of input" when I click on Edit, the error is in </script> and I can't figure out why, all of my tags are closed

<body>
    
    <header>
        ...
    </header>
    <label id="carrello">Il tuo carrello</label>
    <table id="stampa_piatti">
       ....
    </table>
    <div id="bottone_carrello">
        ....
    </div>
    <script>
        if (sessionStorage.getItem("carrello") === null) {
            document.getElementById("stampa_piatti").innerHTML = "<label><div class = 'carrello_vuoto'>Il tuo carrello è vuoto, " + "<a href = 'C:/Users/Admin/Desktop/FastFood/menu_lista.html'>riempilo</a>!</div></label>";
        } else {
            document.getElementById("bottone_carrello").innerHTML = "<div class = 'bottoni_carrello'><button class='button' onclick='acquisto()'>Procedi all'acquisto</button >" +
                "<button class='button' onclick='location.href='file:///C:/Users/Admin/Desktop/FastFood/menu.html';'>Edit carrello</button></div>";
        }
        var t = mostraCarrello();
    </script>
</body>

Solution

  • onclick='location.href='file:///C:/Users/Admin/Desktop/FastFood/menu.html';'

    you need to use a different quote type inside of the quote:

    onclick='location.href="file:///C:/Users/Admin/Desktop/FastFood/menu.html";'

    and since it's already in another quote, probably escape it:

    onclick='location.href=\"file:///C:/Users/Admin/Desktop/FastFood/menu.html\";'

    Or even better:

    document.getElementById("bottone_carrello").innerHTML = `
        <div class = 'bottoni_carrello'>
            <button class='button' onclick='acquisto()'>Procedi all'acquisto</button>
            <button class='button' onclick='location.href="file:///C:/Users/Admin/Desktop/FastFood/menu.html";'>Edit carrello</button>
        </div>
    `;