How to Dynamically Add URL parameters to external URL with button in Repeater using Dynamic fieldkeys

title basically sums it up but, I want to click a button in a Repeater and have a fieldkey in one of my data sets be added to the link that the button goes to. I’m new at coding on Wix so i apologize if my code is wayyyy off and or the Title

this seems to work kinda but only once and only for the first listing in the repeater

import wixData from ‘wix-data’;

export function carfax_click(event, $w) {
carfaxUrl();
}
function carfaxUrl (){
let vin = $w(‘#Vin’).text;
$w(“#carfax”).link = (“CARFAX - Unavailable” + vin)
$w(“#carfax”).target = “_blank”;
}

“vin” in this case is a cars vin number so that once its added it would go to that cars carfax page

Also: If some could show me the code to make a range slider with new slides that filters the repeater based on the range of number fieldkeys

If it’s a repeater, then you should use: onItemReady:
https://www.wix.com/corvid/reference/$w.Repeater.html#onItemReady

Okay well definitely is helpful to know that i need to use that, But I’m still so confused i have nor idea how to set this up this is the mess i came up with

export function Vechicles_itemReady($item, itemData, index) {
const carfax = $item(“#carfax”);
const vin = $w(‘#Vin’);

carfax.src = carfax.img;
vin.text = vin.number;

carfax.onClick( (event) => {
vin.text = vin.number;
$w(“#carfax”).link = (“CARFAX - Unavailable” + vin.number).toString();
$w(“#carfax”).target = “_blank”;
}
);
}

It doesn’t work or do anything lol

in the scope of the onItemReady() function, you should use $item when you refer to a repeater item. don’t use $w .
That includes the elements in the onClick() function (and also $w(“#Vin”) should be $item(“#Vin”) if it is a repeater item.)

Haaazzzaaa It works! but with on small problem, I have to double click the button for it to take me to the url

export function Vechicles_itemReady($item, itemData, index) {
const carfax = $item(“#carfax”);
const vin = $item(“#Vin”);

carfax.src = carfax;
vin.text = vin;

carfax.onClick( (event) => {$item(“#carfax”).link = (‘CARFAX - Unavailable’ + vin.text)
})
}

If someone could let me know how to get it to load in one click that would be sweet

Okay So I figured out how to get it to load in one click,

export function Vechicles_itemReady($item, itemData, index) {
const carfax = $item(“#carfax”);
const vin = $item(“#Vin”);

carfax.src = carfax;
vin.text = vin;

carfax.onClick( (event) => {

{wixLocation.to(‘CARFAX - Unavailable’ + vin.text)}})
}

But I also need it to open in a new tab, which i now know you have to use .target to do, I haven’t been able to figure it out here were the ideas I had:

export function Vechicles_itemReady($item, itemData, index) {
const carfax = $item(" #carfax “);
const vin = $item(” #Vin ");

carfax.src = carfax;
vin.text = vin;

idea 1
carfax.onClick( (event) => {$item(" #carfax ").link = (’ https://www.carfax.com/VehicleHistory/p/Report.cfx?partner=DLR_3&vin= ’ + vin.text).then(results => {let url = results.text; wixLocation.to (url)})

idea 2
carfax.onClick( (event) => { wixData.insert (’ https://www.carfax.com/VehicleHistory/p/Report.cfx?partner=DLR_3&vin= ’ + vin.text).then(results => { $item(" #carfax “).link = (results); $item(” #carfax “).target = “_blank”; // let url = $item(” #carfax ").link; //{ wixLocation.to (url);}})

I’ve tried both and they don’t work, can someone show me the correct way to do this

If you push a link to a button, you don’t need onClick() at all, because links automatically react to clicks. So you have 2 options: 1. Use the link property without onClick() and without wixLocation; 2. Use onClick() + wixLocation.to() without the button.link.
(if you want the target to be “_blank”, you need to go for option1).