Im trying to auto select a option of the state dropdown box with the variable from the url.
For some reason in Safari only, I get this message (undefined is not an object (evaluation 'params.get')) -- not sure why, it only happens in Safari. It works perfect in FF and in Chrome. any thoughts why? Any way to change code to work across all browsers?
jQuery(document).ready(function( $ ) {
// Construct URL object using current browser URL
var url = new URL(document.location);
// Get query parameters object
var params = url.searchParams;
// Get value of state
var state = params.get("state");
state = state.toUpperCase();
//alert(state);
$('#state option').each(function(){
var $this = $(this); // cache this jQuery object to avoid overhead
if ($this.val().toUpperCase() == state) { // if this option's value is equal to our value
$this.prop('selected', true); // select this option
return false; // break the loop, no need to look further
}
});
});