Use an elements text to generate URL

import wixUsers from 'wix-users';
import wixData from 'wix-data';
import wixLocation from 'wix-location';

$w.onReady(function () {
$w("#offerButton").onClick( (event) => {
let slugslug = $w('#text128').text;
wixLocation.to("/usersposts/" + slugslug)
console.log("/usersposts/" + slugslug);
})
});

the screenshot below shows the page the above code runs on (#text128 and #offerButton inside a repeater) #text128 connects to usersPosts which gets a users slug

heres the published page https://billy-95.wixsite.com/newest/ptsbrowse (photo below)

when I click the #offerButton I get this page

note the url: https://billy-95.wixsite.com/newest/usersposts/text128 …it doesn’t get the LOADED contents of #text128

Im trying to link to a page which looks like this:
in editor:


published:

Post your entire code.

Hi I checked your code. i received a error due to missing ) at the end of the event. Try to use a log to track the value of the text. From what I checked, it should work

$w(“#button1”).onClick( (event) => {
let slugslug = $w(‘#text1’).text;
wixLocation.to(“/profile/” + slugslug + “/yourpost”)
console.log(“/profile/” + slugslug + “/yourpost”);
})

Hi there, thanks for the reply, I tried this and it still didnt work. I have changed the URL, but this still doesnt work.

Heres my full page code.

import wixUsers from 'wix-users';
import wixData from 'wix-data';
import wixLocation from 'wix-location';

$w.onReady(function () {
$w("#offerButton").onClick( (event) => {
let slugslug = $w('#text128').text;
wixLocation.to("/usersposts/" + slugslug)
console.log("/usersposts/" + slugslug);
})
});

and heres my the page the code runs on (#text128 and #offerButton inside a repeater)

heres the published page https://billy-95.wixsite.com/newest/ptsbrowse (photo below)

when I click the #offerButton I get this page

note the url: https://billy-95.wixsite.com/newest/usersposts/slugslugslug

I can’t figure out why this isn’t working

Heres the full code, it has changed slightly since my main post but I’m still trying to achieve the same thing. Please see my reply to בונה אדריכלים ומעצבים https://www.wix.com/corvid/forum/main/comment/5e4d953dee7a9c002dc7b819

import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;

$w.onReady( function () {
$w(“#offerButton”).onClick( (event) => {
let slugslug = $w(‘#text128’).text;
wixLocation.to(“/usersposts/” + slugslug)
console.log(“/usersposts/” + slugslug);
})
});

@bill24563 You’ve explained that you’re struggling to link to a specific dynamic URL in a repeater. If I’m understanding correctly, this seems entirely backwards. It seems like you’re linking to the dynamic URL just fine. The real question ought to be: how do I respond at a particular URL and serve the appropriate content?

In other words, where should it link? Give an example of the correct URL. Show what content should appear at that URL. If you’ve taken no action to serve content at this URL then that’s obviously why the page 404s.

@lee1
Heres what i’m trying to link to
editor:

published:

So the contents of #text128 (see screenshot below) should provide the suffix for the URL. On the page below, #text128 is connected to usersPosts dataset, which displays a users slug on the live site.

so the urls im trying to link to are
https://billy-95.wixsite.com/newest/usersposts/myemail9999993
https://billy-95.wixsite.com/newest/usersposts/ myemail11111111x
https://billy-95.wixsite.com/newest/usersposts/ myemail444434343
etc

Oops! I see your mistake now. I should have spotted it sooner not least because it’s a common one we see fairly regularly. You were asking roughly the right questions.

https://www.wix.com/corvid/reference/$w.Repeater.html

Have a read of the above and try to digest it. The code snippet you want to be adapting is this one. You need to use the return value of $w.at to grab the right #text128.

 $w.onReady( function () {
   $w("#myRepeatedImage").onClick( (event) => {
     let $item = $w.at(event.context);
     $item("#myRepeatedText").text = "Selected";
   } );
 } );

Thank you! I’ll give it a read and try again.

I found the solution! I really appreciate your help on this!

If anybody has a similar problem, heres the code I used.
Im not a programmer, but this worked for me!

import wixUsers from 'wix-users';
import wixData from 'wix-data';
import wixLocation from 'wix-location';
$w.onReady(function () {
$w("#text128").onClick( (event) => {
let $item = $w.at(event.context);
let clickedItemData = $item("#text128").text;
wixLocation.to("/usersposts/" + clickedItemData);
});
});