Input Value Redirect

@russian-dima

@madsteer
Ahhhhhhh, i am going crazy xD

The ERROR is in this line —> forgot a closing—> )

else {console.log("No matching data found in DB.")}

@russian-dima

Coding always has something like this xD

Unfortunately, it fixed red error. But still redirecting to the same page.
Also, Why you added 3000ms delay to the code :slight_smile: ?

@madsteer
Just to give you time to take a look into console for 3-secs, because else you will be redirected and you won’t have enough time to take a look onto results.

Perhaps i should just reconctruct all your project and give you a working example instead of theoretical thoughts xD.

One moment …

Here you can test the function and see how it works…
https://www.media-junkie.com/test-database

Working code…

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

//------User-Interface---------
var DATABASE = "TEST-DB" //<---- put in here the ID of your new DB !
var inputDATAFIELD = "index" //<-- put in here the ID of your input- DATAFIELD (INDEX)
var outputDATAFIELD = "url" //<-- This will be the output ---> URL
//------User-Interface---------

var myValue  

$w.onReady(()=>{ 
   $w('#input1').onChange(()=>{
      myValue = $w('#input1').value
      console.log("My value "+ myValue +" setted!") 
 });
 
   $w('#button1').onClick(()=>{console.log("Button-1 clicked!") 
      searchIndex(myValue) 
 }); 
});

function searchIndex(VALUE){console.log("Searchfunction started. Value = ", VALUE)
   wixData.query(DATABASE) 
 .eq(inputDATAFIELD, VALUE) 
 .find()
 .then(async(results) => {
 let items = await results.items; console.log(items)
 if(items.length > 0) {console.log("Item found! Redirection starts in 3-secs.")
 let myURL = await results.items[0][outputDATAFIELD]; console.log("Item-URL: ", myURL)
        wixLocation.to(myURL)
 }else {console.log("No matching data found in DB.")}
 })
}

It has just one little difference to your version. My version uses STRING instead of NUMBERS for —> “index”

The delay of the 3-sec example also works like expected…
Of course you can set any time you need…

setTimeout(()=>{wixLocation.to(myURL)},3000);

Change this code-part and test it by yourself.

@russian-dima No matching data found in DB. I also changed it to my DB id

@madsteer Ok, my friend! xDDDD
I gave you now so much informations, even a working example with code and a table-viewer. If you are not able to solve it till tomorrow, you can contact me on my site or in my profile and i will help you.

Problem solved?