RESOLVED
It was determined that the issue is only on the platform we use thus all answers provided could be probably be right.
This question is based on a previous one
This code of tab selections:
<div class="searchTabContainer col-xs-7" id="searchTabContainer">
<div class="searchTab" id="searchTab1" onclick="javascript:return setActiveTab(1);">MAKE 1</div>
<div class="searchTab" id="searchTab2" onclick="javascript:return setActiveTab(2);">MAKE 2</div>
<div class="searchTab" id="searchTab3" onclick="javascript:return setActiveTab(3);">MAKE 3</div>
<div class="searchTab" id="searchTab4" onclick="javascript:return setActiveTab(4);">MAKE 4</div>
<div class="searchTab" id="searchTab5" onclick="javascript:return setActiveTab(5);">MAKE 5</div>
</div>
Assign classes and create a new var:
$(".searchTab").removeClass("active");
$(".Filter").find("input[type=text], textarea, select").val("");
$("#searchTab" + x).addClass('active');
if (x == 0){
searchBrand = ""
}
else if (x == 1) {
searchBrand = "make1"
}
else if (x == 2) {
searchBrand = "make2"
}
else if (x == 3) {
searchBrand = "make3"
}
else if (x == 4) {
searchBrand = "make4"
}
else if (x == 5) {
searchBrand = "make5"
}
Combined with a homepage link:
<p>
<a href="/search?q=body%20mirrors&type=product">Mirrors</a>
</p>
<p>
<a href="/search?q=body%20air&type=product">Air</a>
</p>
<p>
<a href="/search?q=body%20hydraulics&type=product">Hydraulics</a>
</p>
Gets edited to a new url for searching:
$('.homePageProducts a').each(function(){
var newurl = $(this).attr('href').replace('/search?q=', '/search?q=' + searchBrand + '%20');
$(this).attr('href', newurl);
});
This process works good but when to makes is click subsequently before the final line, both appear in the URL like:
https://www.example.com/search?q=make3%20make5%20%20body%20air&type=product
The default homepage search result without make results to:
https://www.example.com/search?q=%20body%20air&type=product
The question before provided a possible solution to regex but it would also appear that of instead of replacing the homepage url, only insert the searchBrand into the default search url to achieve:
https://www.example.com/search?q=make3%20body%20air&type=product
This might resolve the multiple makes issue. I have tried:
var newurl = $(this).attr('href').insert(10, searchBrand + '%20');
and a few variations of this without success of getting the searchBrand
inserted into newurl
.
How can I achieve this result?
See Question&Answers more detail:
os