I have a google map with markers and when you click on an external link, it takes you to a marker on a map. See js fiddle to see the map in action.

The code on the external link looks like this:

<p><a href="#map" onclick="myClick(0);"><p>Click me</a>
<p><a href="#map" onclick="myClick(1);"><p>Click me 2</a>
<p><a href="#map" onclick="myClick(2);"><p>Click me 3</a>

So a click will take you to the markers 0 1 2 and so forth. The jsfiddle clarifies this. I need those numbers to start at zero so in ee the code looks like this:

<p><a href="#map" onclick="myClick({absolute_count});">{entry}</a></p>

What I want to do is have that {absoulte_count} start with the very first entry which will bring up the first map marker, BUT when I click on it, it takes you to the second marker on the map.

I tried being as clear as I could so comment if you have questions about my question. Ques-ception.

Thanks in advance.


Have you tried myClick({absolute_count}-1); ?

this is needed because {absolute_count} isnt zero-based and starts at 1

Or you can subtract the id by 1 in your myClick function

function myClick(id) {
    id = id-1;
    google.maps.event.trigger(markers[id], 'click');

There is also an addon http://devot-ee.com/add-ons/mh-index for this.

  • Adding the '-1' did the job, thanks!
    – ObiWanKobi
    Mar 24 '14 at 6:31

I'm not entirely certain if the variable will be available in this context but try using {count} instead of {absolute_count}.

{count} starts from 1.

{absolute_count} is zero indexed so will always start from 0.

  • Initially I used {count} and it didn't work but thanks for the input.
    – ObiWanKobi
    Mar 24 '14 at 6:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.