Click here to Skip to main content
15,881,850 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
The below script works perfectly fine on Google Chrome only and doesn't work on Firefox or IE


JavaScript
//I created the script at the bottom of the body to change select dropdown based on currently selected mainheading value.
//old method tried to use scriptlets mixed with javascript, but it's easier to do this with javascript.
const urlParams = new URLSearchParams(window.location.search);
const myParam = urlParams.get('mainHeading'); 
//if mainHeading parameter is null or equal to  Operations show  Operations dropdown
if(myParam === ' Operations' || myParam === null) {
	document.getElementById('mainHeading').value = ' Operations';
}else{
	document.getElementById('mainHeading').value = ' Future Plans';
}


What I have tried:

If I change the order of the if statement to the below, then the only option available in the drop down list is "Operation" and the second option "Future Plans" never shows up

var urlParams = new URLSearchParams(window.location.search);
var myParam = urlParams.get('mainHeading'); 
//if mainHeading parameter is null or equal to Operations show Operations dropdown
if(myParam ==='Future Plans'){
	document.getElementById('mainHeading').value = 'Future Plans';
}else{
	document.getElementById('mainHeading').value = 'Operations';
Posted
Updated 15-Nov-18 0:52am
v3

1 solution

URLSearchParams - Web APIs | MDN[^]

There is a compatibility list at the bottom.
 
Share this answer
 
Comments
Member 14055416 15-Nov-18 4:52am    
Thank you! I am completely new to JavaScript and never worked with it in the past. How would you fix the script above to make it work with Firefox and/or Safari/IE please? Your help is so much appreciated. Thank you
Richard Deeming 16-Nov-18 10:44am    
Use a "polyfill" script - for example: https://github.com/WebReflection/url-search-params[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900