.eq with variable numbers

I’m currently using the code:-

export function postsearch_click(event) {
var userpost = $w(“#postin”).value;
wixData.query(‘Dealer’)
.eq(“postcode”, userpost)
.find()
.then( (results) => {
let items = results.items;
let firstItem = items[0];
$w(“#postout”).value = firstItem.location;
} )
}

If I change the .eq(“postcode”, 3000) it works, I just don’t know how to make the 3000 in this case work with a variable number that is being inserted from a textbox.

1 Like

Hi,
The input you get from the input component comes as a string.
Is there any chance that ‘postcode’ in your database is a number?
If so, you can just use parseInt function to convert the string to a number:

const userpost = parseInt($w("#postin").value);

Hope this helps,
Liran.

Thanks heaps that worked, the only thing I changed from the code you gave me is made it:

const userpost = parseInt($w(“#postin”).value, 10);

Just to get rid of the radix warning and making it say that it should be using the decimal system.