Results 1 to 2 of 2

Thread: Need help with disable

  1. #1
    Join Date
    Mar 2009
    Posts
    43
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Need help with disable

    Hi everybody.

    Could someone help me make it so this script disables all buttons and textareas and stuff BESIDES whats in the function named "on()" ?

    for example

    if theres 2 buttons in on, a button named "one" and a button called "2", it will disable EVERYTHING BUT the buttons one & two

    Code:
    function on(){
    disableForm(document.forms.calculator.one);
    disableForm(document.forms.calculator.two);
    }
    
    function disableForm(thename) {
    var numberForms = document.forms.length;
    var formIndex;
    for (formIndex=0; formIndex<numberForms; formIndex++)
    {
    for(x=0;x<document.forms[formIndex].length;x++)
    if(document.forms[formIndex].elements[x] +== thename){
    document.forms[formIndex].elements[x].disabled=false
    }else{
    document.forms[formIndex].elements[x].disabled=true
    }
    }
    }
    thank you!

    ~Shadow~

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Code:
    function on(){
      disableForms({one: 'calculator', two: 'calculator'});
    };
    
    function disableForms(exceptions){
      var numberForms = document.forms.length, formIndex = 0, x, n;
      for (formIndex; formIndex < numberForms; ++formIndex){
        for (x = 0; x < document.forms[formIndex].elements.length; ++x){
          n = document.forms[formIndex].elements[x].name;
          if (exceptions[n] && exceptions[n] === document.forms[formIndex].name){
            document.forms[formIndex].elements[x].disabled = false;
          }
          else {
            document.forms[formIndex].elements[x].disabled = true;
          }
        }
      }
    };
    Last edited by jscheuer1; 04-28-2009 at 06:55 AM. Reason: minor code improvements
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •