Use the same datalist for multiple pages

Asked

Viewed 56 times

0

I’m wanting to make a system where I would have a datalist with all my options and on every page of my site would be mirrored. Example:

<input type="text" name="tCid" id="cCid" placeholder="Insira uma opção" list="cEst" />
<datalist id="cEst">
    <optgroup label="Séries Ativas">
        <option disabled>Opcao1</option>
        <option disabled>Opcao2</option>
        <option value="Opcao3">Opcao3</option>
        <option disabled>opcao4</option>
        <option disabled>Opcao5</option>
    </optgroup>
</datalist>

In that case, you’ll get one input for the user to write an option and select it. Only that I want this one datalist be unique to all pages on my site. That is, when I take the disabled of Opcao1 and put value="Opcao1", it should update from every page of my site that has that tag datalist.

  • Why not do it in a php file?

  • I’d rather not do with php @Andersonhenrique

  • Angularjs?

  • It can be any JS @Andersonhenrique, but you have to help me because I don’t know how it works.

1 answer

0


For those who also want to know, I did it this way:
I put in a file . txt all lines of code that I wanted to mirror on all pages.
Then I used the following script to make it happen:

<script>
document.getElementById("cCid").onchange=function(){ 
    //this.value tem o valor que foi escolhido nas opções
    window.location.href = "https://www.site.com/series/" + this.value + "/index.html"; 
}</script>



Basically, I made the script add the entire file . txt in place of the code this.value, doing what PHP would do much easier, but did not want to do with PHP. I hope I helped someone

Browser other questions tagged

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