Document.referrer.indexOf - how to select/click element in links drop down options


I have the following code which individually works, but I don’t know how to put it together in JavaScript…

if document.referrer.indexOf(‘Belgium’)>0

then (“a.optionLink:contains('Belgium”+“')”).click();

else (“a.optionLink:contains('England”+“')”).click();

Any chance you could show me how to script this??

Hi Stevvo,

Is this what you’re after?

if (document.referrer.indexOf('Belgium') > 0) {
} else {

Youre a genius!!! thanks!!!

If I want to add a few more options, eg France, Spain, Brazil is that possible???

thanks very much fretburner

What is it that your code does? If it finds the name of the country in the url, it clicks on a link, but what does that link do? I only ask because there might be an easier way depending on what you’re trying to achieve.


when you click onto the search page from a country page the code automatically picks up the country from the last URL then automatically selects that country from the drop down option link list, rather than you manually selecting it once on the search page. I’ve got a whole load of countries to add, but I’ve noticed that it may need an on load first because although the country is now selected it has not changed the search results from the default provision…!!

Does that help? I’m very new to this.

Thanks for your help.

It sounds like you might be better off passing the country in the URL (e.g. That way you can render the page with the correct results without needing any JS, and it would also allow the user to bookmark the link and come back to it later.

Ok, cool, will look at that.
Thanks for your help.