If condition is met for string-> redirect to page

Hello you guys, I’m completely new to wix code and I have been trying to figure something out for the last two hours.

I have a Text Input called input1. Now I have created a button = button3. On click this button I want it to check the string value of input1 is equal to for instance ‘a’ and if that is the case redirect the visitor to the location /1.
Here is my code for now. I want to add several links according to the answer in Input1

import wixLocation from ‘wix-location’;
export function button3_click(event, $w) {
var pass= $w(‘#input1’)
if (pass===‘a’) { wixLocation.to(‘/1’);
} }

I also tried this code:
import wixLocation from ‘wix-location’;
export function button3_click(event, $w) {
var pass= $w(’ #input1 ‘)
var a = ‘one’
var b = ‘two’
if (pass===‘a’) { wixLocation.to (’/1’); }
else if (pass===‘b’){ wixLocation.to (‘/2’); } }

This code offcourse works:

export function button4_click(event, $w) {
wixLocation.to(‘/1’)
}
Thanks in advance,
I’ll keep trying.

Hey @mathiaspeters ,

To get the value of an input field:

var pass = $w('#input1').value;

See $w.TextInput.value for more information.

To compare the value:

var a = 'one'
if(pass === a)

You need to compare one variable with another.

Since you say that you are “new to Wix Code”, I would suggest reviewing the Wix Code Basics.

Have fun,

Yisrael

Hey thanks for your suggestion and fast answer. I will try to implement it now.