Navigating to page defined by dynamic page element

This is what I am trying to do:
A user is on a dynamic page and presses a button. The user is then redirected to another page on my site which is determined by the text value on the dynamic page. This text value is linked to the dynamic dataset.

So, for example, I have a text box on a dynamic page that is linked to the field “pagename” in the dynamic dataset. Let’s suppose that field has the value “pageiwanttonavigateto”. I want the user to navigate to www.mysite/pageiwanttonavigateto

I used the code below, which almost works, except that instead of using the text value from the dynamic dataset (“pageiwanttonavigateto”) it navigates to the text in the box that is supposed to be replaced by the dynamic dataset value (e.g. if I have an “x” in the text box, it will navigate to instead of

Any suggestions? My code is below.

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

$w.onReady( function () {
let newvalue = $w(“#text1”).text;
$w(“#button1”).onClick( (event, $w) => {‘/’ + newvalue);
} );

i think you should try this:

let myValue = $w("#myElement").value; // "42"

text is meant for textbox and not for user input$w.TextInput.html#value


Thanks Schlomi! I tried this edit but got an error: ‘value’ does not exist on ‘#text1

can you please share the url of your page?


Here is my page url:

I have also tried dropdown and input boxes instead of textboxes, but in all cases the variable “newvalue” is defined by whatever pre-populates the input element (e.g. placeholder text, etc) rather than the value defined by the connected dataset.

Thanks for your help!

Hello dbaxter, i am also trying to find out a way to link an element of a dynamic page to another page which a determined by text value of that perticular element showing on the dynamic page. If you find the solution to your problem then please share it with me.

Hi David,

please note that in your code you have to events on the user viewing the page ‘timeline’:

  1. when the page is first displayed - $w.onReady (whatever you write here executed on ready)
  2. when the button was clicked - .onClick(whatever you write here executes on button4 click)
    so you might want to put the new value creation on the button4 click
$w.onReady(function () {
 let newvalue = $w("#input11").value;
  $w("#button4").onClick( (event, $w) => {'/i/' + newvalue);
} );


$w.onReady(function () {
  $w("#button4").onClick( (event, $w) => {'/i/' + $w("#input11").value);
} );

i could not find input11 in your page so i couldnt really understand what you are trying to do eventually
maybe you also want to redirect only onAfterSave


That appears to have worked, thanks Schlomi!

I have similar Problem when my page directs to DynamicPage, the page displayed is not the correctone eve the URL is Correct, Page displays correctly after I refresh my page.
Any suggestions?