Home > other >  Calling Select Tag from URL
Calling Select Tag from URL

Time:06-21

I have a webpage with a <select> tag called dropDown with selectable options 'OptionA', 'OptionB' and 'OptionC'.

It is possible for me to link to the webpage and call one of the options from the URL?

For example: smaple.aspx?dropDown=OptionB

CodePudding user response:

You can get the GET parameter with JavaScript

let params = new URLSearchParams(document.location.search);
let dropDownValue = params.get("dropDown");

then change the select value with JavaScript(assume the select element has a id called a-dropdown)

document.getElementById('a-dropdown').value = dropDownValue;
  • Related