'Script not working on iPhone6 Safari and Chrome
I've got a Wordpress form (Fluent Forms Pro) with a dropdown list, and some jQuery loading in the footer that automatically chooses an item from the list depending on the querystring 'category' value.
It works everywhere apart from on iPhone Safari and Chrome on an iPhone 6. Can anyone see why it's not working on those devices?
if (typeof urlParams !== 'undefined') {
const urlParams = new URLSearchParams(window.location.search);
} else {
urlParams = new URLSearchParams(window.location.search);
}
myParam = urlParams.get('category');
(function($) {
$.expr[':'].icontains = function(a, i, m) {
return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase()) >= 0;
};
$('.form-category-select option:icontains(' + myParam + ')').each(function() {
if ($(this).text().toLowerCase() == myParam.toLowerCase()) {
$(this).attr('selected', 'selected');
return false;
}
return true;
});
})(jQuery);
The jQuery selects the correct option name (not value) compared to the 'category' querystring (case insensitive):
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<select name="form_element" id="ff_6_form_element" class="ff-el-form-control form-category-select" type="select" data-name="form_element" data-calc_value="0" tabindex="1">
<option value="">- Select -</option>
<option value="87">Category 1</option>
<option value="124">Category 2</option>
<option value="79" selected="selected">Category 3</option>
<option value="190">Category 4</option>
<option value="138">Category 5</option>
<option value="108">Category 6</option>
</select>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
