Replace php include for javascript

Asked

Viewed 220 times

-2

I am making a website that I am required to use HTML, CSS and Javascript at most. It’s just that many things I need Php I can’t use.
So I’ve been searching for a synonym of include() and found the following, which helped in parts:

        <select id="cidade" name="cidade">
            <option selected disabled>-- Selecione uma cidade --</option>
            <option value="atibaia">Atibaia - SP</option>
            <option value="bragancapta">Bragança Paulista - SP</option>
        </select>

<script>
document.getElementById("cidade").onchange=function() {
    document.getElementById("inserir").innerHTML = "<object type='text/html' data='cidades/" + this.value + "/index.html' width='100%'>";
}
</script>
<p id="inserir"></p>

Okay, but what’s the problem? It creates a scroll bar on the side. I know how to remove with CSS, but the text that was inserted scrolls only within the div and I wanted to make it as if the inserted text is part of the page, as it works in include() of Php. The question is, how do the mechanics of Javascript in that case it shall be the same as Php?

Print to illustrate: https://imgur.com/a/V9AGLgB

  • Increase the element size with the attribute height (via CSS)

  • This happens because you are loading in p as if it were a new html, so the bar, pq used object?

  • @Valdeirpsr got more or less in his comment.

1 answer

0


I managed to resolve with the help of Valdeir Psr in the comments. He gave a right suggestion in the wrong way. I just added this in my CSS:

object {
height: 100%;
}

And already answering Leandrade, I used object because he was the one who best served me in this application of my code HTML and also all tutorials and applications in the same way suggested to use object. I can even search for a more optimized tag later, but this has served me for now.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.