[Solved] Issue with on.click function for Box to appear

Hello,

I created a Code to check my database for a user.
After clicking the “Zustimmen Button” a box should appear with the on.click function, if the user was found in my database.
If this user was not found then a Submit-Button should appear.

Somehow the Submit-Button always appear after one click, even if the user is in the database. Meanwhile, when I click the second time on the “Zustimmen Button” then the box appears.

So the user is found, but the box just appears after 2 clicks.

Here is the Code:
export function ZustimmenButton_click ( event,$w ) {
wixData . query ( ‘MitgliederGateway’ )
. eq ( “copyOwner” , $w ( ‘#MemberCopyOwner’ ). value )
. find ()
. then (( res ) => {
if ( res.totalCount > 0 ) {
$w ( ‘#box2’ ). show ();
}
else {
$w ( ‘#SubmitButton’ ). show ();
}
})

}
Any ideas, what is causing that and how can I fix it?
Thanks

Hi! It seems like there might be an issue with the timing of the show() function. One solution could be to add a delay before showing the box with setTimeout function. Give the database query enough time to finish before showing the box. You can adjust the delay time as needed to find the optimal timing.

Thanks for the hint
Seems to work