[Project_owners] Disable OK button in dialog

Chad House chadh at pobox.com
Thu Mar 18 15:20:09 EST 2004


Gustavo Araujo Bittencourt <g.bitten at bol.com.br> writes:

> I am sure there is a very obvious way to enable/disable OK button in
> dialog via javascript.
> I tried this:
>   document.getElementsByAttribute("label","OK").item(0).setAttribute("disabled",
>   "true");
>   document.getElementsByAttribute("label","OK").item(0).removeAttribute("disabled");
> But returned error

You can use the 'getButton' method of Dialog. Suppose you've defined
your dialog in XUL like so:

  <dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
          id="my-dialog" 
          title="My Random Dialog"
          buttons="accept,cancel" 
          ondialogaccept="accepted()"
          ondialogcancel="canceled()"
          onload="loaded()">
    <script type="application/x-javascript" src="mydialog.js"/>
    <vbox>
      <!-- More content here ... -->
    </vbox>
  </dialog>

and you want to disable the OK button (technically the 'accept'
button) when loaded. In your onload handler, you simply do something
like:

  var dialog = document.getElementById('my-dialog');
  var button = dialog.getButton('accept');
  button.disabled = true;

Cheers,

Chad


More information about the Project_owners mailing list