Is there a way to code a button so that it will enable another button only if a valid entry has been made in an input field

I’m trying to code a sort of quiz website. I’ve already figured out how to use the pattern validation to allow only the correct answer in the input field, and how to use the on_click function to enable the continue button, but I can’t seem to tie the two together properly. Here’s my current attempt, does anybody know where I’m going wrong here?

export function button4_click(event) {
//Add your code for this event here:
let answer = $w( ‘#input1’ );

if (!(answer.valid)) {
$w( “#button2” ).disable();

} **else** { 
    $w( "#button2" ).enable();   
} 

}

Hey!

Here is the easiest way :

You would have to of course adjust it to the logic that you want and that suits your needs (eg do the validation once you click the button) but it can give you an idea on the easiest set up

Good luck!

exportfunction button4_click(event) {
//Add your code for this event here:
if ($w('#input1').valid) {
$w("#button2").enable();    
} else {
$w("#button2").disable();
}
}

thanks!