Alert message when field is certain value

Hello,
I am trying to create a popup for when a field is a certain value. I am using SharePoint 2016 Forms Designer. My field is Cancel Request. I put this in the javascript field.
function alert() {
if (fd.field('Cancel_x0020_Request').value() == 'Yes') {
alert("Are you sure you want to cancel");
}
}
fd.field('Cancel_x0020_Request').change(alert);
alert();

Cancel_x0020_Request is the internal name. It is giving me a odd message in the browser.
Capture
Capture2

Is there something I am missing? I have the code in the top of the javascript.

Hello @David_E_Garza,

The name of the function should be unique. And as alert function is already exist, you are getting the error. So you just need to rename the function, e.g. alertUser:

function alertUser() {
if (fd.field('Cancel_x0020_Request').value() == 'Yes') {
alert("Are you sure you want to cancel");
}
}
fd.field('Cancel_x0020_Request').change(alertUser);
alertUser();

Please, post questions regarding Forms Designer to theForms Designer Forum. Thank you!

1 Like

I feel dumb. That worked. Thank you again for your help.

1 Like

when using Plumsail Forms, where do you place this code?
Thanks

Hello @eweiler,

Using Plumsail Forms, you need to add the code to the JavaScript Editor:
image

And you need to slightly change the code, as Plumsail Forms JS API is different from Forms Designer.


fd.spRendered(function() {
    function alertUser() {
        if (fd.field('FieldName').value == 'Yes') {
            alert("Are you sure you want to cancel");
        }
    }
    //cal function on field change
    fd.field('FieldName').$on('change', alertUser);
    //call fucntion on form load
    alertUser();
});

You can find more information in our documentation here.

1 Like

Ok, i put this into the form and I don't get any pop up no matter the value of the field

image

It's a Boolean field, so I changed it, but still same thing. nothing

image

I figured it out. This works! thanks again

image

1 Like

Is it possible to change the font size and color of the alert box?

Hello @adasilva,

Alert box is a system object so you can't change its styling. As an option, you can design a custom confirm box, please find the example here.