Prevent Multiline text box from clearing

Hi Plumsail,

I have a checkbox which runs a function that shows, hides and clears a multiline text box field. When I click the checkbox, it always clears the field which contains text.

Is there a way to warn users and make them confirm a browser dialog before it hides and clears the multiline text box field?

I'm aware of the "Confirm()" method but I don't know how to prevent hiding and clearing a multiline text field.

function ShowHideSVHealthierLivesMLTF2(){
    
    if (FD_SVCheckboxes.value.indexOf("Healthy lives")>=0){
        //hide field
        $(FD_SV_HealthierLivesMLTF.$parent.$el).show();
    } else{
        $(FD_SV_HealthierLivesMLTF.$parent.$el).hide();
        FD_SV_HealthierLivesMLTF.clear();
    }
}

Thank you for your help!

Hi @Qman,

Could something like this work for you?

function ShowHideSVHealthierLivesMLTF2(){
    if (FD_SVCheckboxes.value.indexOf("Healthy lives")>=0){
        $(FD_SV_HealthierLivesMLTF.$parent.$el).show();
    } else{
        let clearAndHide = true;
        if (FD_SV_HealthierLivesMLTF.value) clearAndHide = window.confirm('Clear and hide field?'); // only prompt the user if there's something to clear
        
        if (clearAndHide) { // only clear the value if the user chose to
            $(FD_SV_HealthierLivesMLTF.$parent.$el).hide();
            FD_SV_HealthierLivesMLTF.clear();
        }
    }
}