search

Home  >  Q&A  >  body text

Use href to automatically select an option from a dropdown list

I'm trying to make a dropdown automatically select an option based on the href (stored in the address bar) obtained from the button pressed on the previous page. I've tried looking up this question but can't seem to find anything relevant, so I can only assume my wording is wrong or this isn't possible.

This is my code from index.html

<div class="logo-row">
   <img src="./assets/img.png" onclick="function();" class="logo"/>
   <a href="./page1.html#sprites"><img src="./assets/sprites_placeholder.png" class="button p1"/></a>
   <a href="./page1.html#models"><img src="./assets/models_placeholder.png" class="button p1"/></a>
   <a href="./page1.html#textures"><img src="./assets/textures_placeholder.png" class="button p1"/></a>
   <a href="./page1.html#sounds"><img src="./assets/sounds_placeholder.png" class="button p1"/></a>
</div>

This is the code in page1.html

<div class="custom-select">
   <label class="resource">Resource:</label>
   <select id="selectBox" onchange="changeResource();">
      <option value="1" id="sprites">Sprites</option>
      <option value="2" id="models">Models</option>
      <option value="3" id="textures">Textures</option>
      <option value="4" id="sounds">Sounds</option>
  </select>
</div>

I'm not entirely sure this describes what I'm trying to achieve, but when I tested it with just plain text, it loaded just fine.

P粉358281574P粉358281574276 days ago420

reply all(1)I'll reply

  • P粉086993788

    P粉0869937882024-02-27 07:48:08

    You can get the hash ID from the url and then set the selected element from the dropdown using javascript

    reply
    0
  • Cancelreply