Skip to main content
frameexpert
Community Expert
Community Expert
August 31, 2012
Answered

Validate dialog on OK button or Enter key

  • August 31, 2012
  • 1 reply
  • 776 views

I have a dialog with a bunch of checkboxes and OK and Cancel buttons. When the user clicks OK or presses Enter, I want to validate the other controls and keep the dialog open if none of the checkboxes are checked. I know how to test the checkboxes, but I am not sure how to do this with an event handler and keep the dialog open. Any suggestions or pointers would be appreciated.

Rick

This topic has been closed for replies.
Correct answer CarlosCanto

here is one way of doing it

var w = new Window('dialog');

var chk1 = w.add('checkbox', undefined, 'check 1');

var chk2 = w.add('checkbox', undefined, 'check 2');

var btnOk = w.add('button', undefined, 'ok');

var btnCancel = w.add('button', undefined, 'cancel');

btnOk.onClick = function () {

          //alert('click');

          checked ();

}

btnCancel.onClick = function () {

          //alert('cancel');

          checked ();

}

w.show();

function checked () {

          if (chk1.value || chk2.value)

                              alert('checked');

          else

                    alert('unchecked');

}

1 reply

CarlosCanto
Community Expert
CarlosCantoCommunity ExpertCorrect answer
Community Expert
August 31, 2012

here is one way of doing it

var w = new Window('dialog');

var chk1 = w.add('checkbox', undefined, 'check 1');

var chk2 = w.add('checkbox', undefined, 'check 2');

var btnOk = w.add('button', undefined, 'ok');

var btnCancel = w.add('button', undefined, 'cancel');

btnOk.onClick = function () {

          //alert('click');

          checked ();

}

btnCancel.onClick = function () {

          //alert('cancel');

          checked ();

}

w.show();

function checked () {

          if (chk1.value || chk2.value)

                              alert('checked');

          else

                    alert('unchecked');

}

frameexpert
Community Expert
Community Expert
August 31, 2012

Excellent, Carlos. Thanks!

Rick

www.frameexpert.com