Skip to main content
Known Participant
March 23, 2021
Answered

Javascript to have yes or no window

  • March 23, 2021
  • 3 replies
  • 1657 views

Can anyone help me with creating a yes or no popup window in photoshop cc when we run the javascript and based on yes or no function 1 or function 2 execute accordingly.

This topic has been closed for replies.
Correct answer Charu Rajput

Hi,

Try following simple script

#target photoshop
function showDialog() {

    var dlg = new Window("dialog", "Sample Dialog");

    var buttonGroup = dlg.add('group', undefined, '');
    // buttonGroup.alignment = 'right';

    var yesButton = buttonGroup.add('button', undefined, 'Yes', {
        name: 'Yes'
    });

    yesButton.onClick = function () {
        alert('You click yes button.')
    };


    var closeButton = buttonGroup.add('button', undefined, 'No', {
        name: 'No'
    });

    closeButton.onClick = function () {
        alert('You click No');
        dlg.close();
    };

    dlg.show();

}

showDialog();

 

 

3 replies

Stephen Marsh
Community Expert
Community Expert
March 23, 2021

To flesh out r-bin's reply with code snippet:

 

var confirmationDialog = confirm('Your question here...');
// Test if no returns false, then terminate the script - otherwise continue the script
if (confirmationDialog === false) {
    alert('Script cancelled!');
    return;
}
Legend
March 23, 2021

Charu Rajput
Community Expert
Charu RajputCommunity ExpertCorrect answer
Community Expert
March 23, 2021

Hi,

Try following simple script

#target photoshop
function showDialog() {

    var dlg = new Window("dialog", "Sample Dialog");

    var buttonGroup = dlg.add('group', undefined, '');
    // buttonGroup.alignment = 'right';

    var yesButton = buttonGroup.add('button', undefined, 'Yes', {
        name: 'Yes'
    });

    yesButton.onClick = function () {
        alert('You click yes button.')
    };


    var closeButton = buttonGroup.add('button', undefined, 'No', {
        name: 'No'
    });

    closeButton.onClick = function () {
        alert('You click No');
        dlg.close();
    };

    dlg.show();

}

showDialog();

 

 

Best regards
Known Participant
March 23, 2021

Thank you. Works well.