The answer of Avinash was very helpfull. The only thing was missing was the urlParams. I have updated his code, hope this helps!
Page 1:
<a href="page2.html?q=feedback"> Request Feedback</a>
Page 2:
<select name="subject" id="subject">
<option value="feedback">Feedback</option>
<option value="comment">Comment</option>
<option value="question">Questions</option>
</select>
<script>
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const q = urlParams.get('q')
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
//This is for default value of the select
if (q) {
document.getElementById("subject").value = q;
}
</script>