Set button link to different Anchor, located in a repeater connected to a dataset

Hi all,
i create a repeater in which there is a button. This one must link when clicked to an anchor in another page. I know i can set the ancor but in this way it will be the same for each item of the repeater. I wanna link the button of each item of the repeater to different anchors and not to a only one. The best is to find a way to write the anchor in the dataset. Thank in advance for the help :slight_smile:

Hello

You can do that using code, what i would suggest is the following:

  • Add button click event (Button’s Properties panel)

  • On click get the current item that was clicked.

  • Set an indicator of the button in the session (title of item for example).

  • Use wix location to go to the page with anchors.

  • On page ready (in the page with anchors) check the session value and scroll to the wanted anchor.

Here’s a code example of how it would look like on the repeater’s page:

import {session} from 'wix-storage';

export function button1_click(event, $w) {
 //Add your code for this event here: 
 let repeaterItem = $w('#repeaterData').getCurrentItem();
    session.setItem("key", repeaterItem.title);
    wixLocation.to("/Anchors page");    
}

On the other page you just get the session value and scroll to it’s anchor.

I hope this helps!
Massa

Thank you for the help :slight_smile: what do you mean with " you just get the session value and scroll to it’s anchor. ". Could you write me an example? For the first part all is ok :slight_smile:

Hello

here’s a code example to add on the anchors page, however you can check the documentations linked above to know more about the session and scroll to function :slight_smile:

import {session} from 'wix-storage';
$w.onReady(function () {
 //TODO: write your page related code here...
 let anchorKey= session.getItem('key')
 //you can use if statements or swich cases
 if (anchorKey === 'value1') {
        $w('#anchor1').scrollTo();
    }else{
        $w('#anchor2').scrollTo();
    }

});

Best
Massa

Hi Massa,i want to achieve this but with a database ( https://www.wix.com/corvid/forum/community-discussion/how-to-work-with-anchor-and-database )

if its from button we can set item like this as your direction :

let repeaterItem = $w('#repeaterData').getCurrentItem();
    session.setItem("key", repeaterItem.title);
    wixLocation.to.to("/Anchors page");    
}

but how if the link is from database which i can’t create session.setItem there

hi
I use the code shown and replaced the values but its not working ,i used #repeterdata with repeter name and value 1 with button text . what exactly are those values , i am new to wix.

This is an old thread and will be closed, for more questions feel free to open up a new thread.