Search bar and button for (Database)Help please

hi everyone …

I have database contain 2 field Number and link as shown in the pic down

what’s the code when i enter number 1 the site go to Link in the site field in database


because i try many codes and nothing happens :frowning: :frowning:

please helppppppp :frowning: :confused:

[@9M RJ] I suggest you spend a little more time reading the articles on datasets. Specifically the API documentation for setFilter. There are several problems that you need to understand.

  1. Your click function is called searchButton_click. The button in the Editor seems to be button1. Unless you changed the default binding (which would be button1_click) then this function will not catch the click event.

Now you are confusing the wix-data API with the wix-dataset API. To do what you seem to be trying to do you should probably ignore the dataset and focus on using the wix-data API.

You have already started to write the query using wixData. So simply finish it off and remove the $(“#dataset1”).setFilter code.

You will get the result you need like so:

wixData.query(“App”).contains(“site”, SearchValue).find()
.then((result) => {
if (result.length > 0)
{
let destination = result.items[0].site;
wixLocation.to(destination);
}

});

I suggest you look up the API functions I have used here and familiarize yourself with what they are doing.

Hope this helps you out.

Steve

1 Like

[@Steve Cropper] still not work :frowning: really this website so easy but take all my time and backing to same point

@mhamadrajab91 Can I suggest that you try to be more precise with your request?

" still not work" doesn’t help forum members understand what your error is. You have not shown how you took the suggested code and applied it on your page. If you used the code incorrectly then it won’t work. :slight_smile:

There are many things that can be preventing your code from working. Unfortunately you are not giving enough information to help solve your problem.

You are only showing lines 8 - 12 of your Page code there is other code that you are not showing.
For example on line 8 you begin the declaration of the function

export function searchButton_click() {

but you do not end the function…

}  // The end function brace is missing from what you show

You do not show the Properties panel for your button which is named “button1” not “searchButton”.


So unless your Property panel for the button is connected to searchButton_click the function will never be called. I don’t know if you have this connected correctly or not, you haven’t shown that information.


You do not say what the page url is so that it can be examined for other problems.

There are many examples of how to make these connections on the Wix Code minisite

You also need to make sure that the type of the Number column in your data collection is usable in the wixData.query() contains() function call.

The value returned from the $w(“#input1”).value property will be a string. If the Number column is set up as a Number type then you also need to convert the $w(“#input1”).value to a Number type:

let SearchValue = Number($w("#input1").value);

See Number - JavaScript | MDN

Finally make sure you read and understand these references:

Cheers
Steve

1 Like

@stevendc hi steve i wish you have great time
i did all of it and still same when i enter the number and press search still nothing happend
the code is:

export function button1_click(event) {
//Add your code for this event here:
let SearchValue = Number($w(“#input1”).value);
wixData.query(“App”).contains(“site”, SearchValue).find()
.then((result) => {
if (result.length > 0)
{
let destination = result.items[0].site;
wixLocation.to(destination);
}
}

    )}

help :frowning:

Help please :frowning:

What is the url of your web page?

1 Like

https://9mrjiphone.wixsite.com/apps

@Steve Cropper

@mhamadrajab91 OK So a couple of things

You are using a Number type in your data collection. This means that you cannot use contains so the following will not work.

wixData.query("App").contains("site", SearchValue)

This is why I suggested that you read the documentation. The contains() API document states:

contains( )

Refines a query or filter to match items whose specified property value contains a specified string.
You need to use the .eq() function .

eq( )

Refines a query or filter to match items whose specified property value equals the specified value.
In addition you are searching the site field. The number you are trying to search for is actually in the number field.

So your code should look like this:

wixData.query("App").eq("number", SearchValue)

In addition the code to load a new web page will only work on your published site. If you add a console.log statement before the call to wixLocation.to(destination) you will see that the correct value is returned by your query…

export function button1_click(event) {
    //Add your code for this event here:
    let SearchValue = Number($w("#input1").value);     
    wixData.query("App")
    .eq("number", SearchValue)
    .find()
    .then((result) => {
        if (result.length > 0) {
            let destination = result.items[0].site;
            console.log(destination); // <<< Display selected link  
            wixLocation.to(destination);
        }
    })
}

Good luck
Steve

1 Like

@stevendc Thank u steve million thanks it’s work now <3