Set HTML Dropdown Through search bar address

Viewed 24

I have a server login page, than I access through microsoft edge. When the page loads, i have to enter my Username & Password.

I also have to select a 'Security Doman' using a dropdown menu. The menu has 2 options, and it's always the second option i need to select.

div class="security-domain">
<div class="flabel" id="namespaceLabel">Security Domain</div>

<select class="infaField" name="namespace" id="namespace" onchange="onSelectionNamespace()">

  <option value="Native">Native</option>

  <option value="Company.Local"> Company.Local</option>

</select>

</div>

Is there a way I can set this dropdown in the webiste link? Something like

www.website.com/?namespace='Company.local'

I have very little HTML experience, so any advice would be apprecaited

Cheers Caleeco

1 Answers

You can't do it with HTML alone, but with a bit of JavaScript; URLSearchParams is useful for parsing query strings, and you can find the current query string in location.search:

const params = new URLSearchParams(location.search);
document.getElementById("namespace").value = params.get("namespace");
Related