Enable/Disable button

I have a checkbox and a button (disabled by default). I am trying to enable/disable the button based on the value of the checkbox. The button is disabled when the page loads, but I would like to enable it once the user acknowledges the action by checking the checkbox. I can’t seem to get the button to enable. I have tried using Set-UDElement and also Invoke-UDJavascript to do this. Please help.

New-UDCheckbox -id 'deletecontent' -Label 'Would you like to delete the content found in the search results?' -OnChange {
$element = Get-UDElement -id 'deletecontent'
    if($element.Attributes["checked"]) {
    	Invoke-UDJavaScript -Javascript "document.getElementById('delete').disabled = false;"  
            Sync-UDElement -id 'delete'
    }
    else {
            Invoke-UDJavaScript -Javascript "document.getElementById('delete').disabled = true;"                                
            Sync-UDElement -id 'delete'
    }

}

New-UDButton -id “delete” -Text “Delete” -Disabled -OnClick {
$DeleteContent = (Get-UDElement -id ‘deletecontent’).Attributes.checked
if($DeleteContent){
'Delete some data
}
}

OK, I figured it out…
if($element.Attributes[“checked”]) {
Set-UDElement -Id “delete” -Attributes @{disabled = $false}
}
else {
Set-UDElement -Id “delete” -Attributes @{disabled = $true}
}

8 Likes