SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard boxhead's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    1,040
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    variable used to disable button

    Why doesnt this code work?

    function lbClick(criteria) {
    var selFrom = "lbLeft"+criteria
    var addBut = "cmdAdd"+criteria
    var remBut = "cmdRemove"+criteria
    var oButton = (event.srcElement.id==selFrom) ? addBut : remBut;
    oButton.disabled = false;
    }

    the button is called cmdAddArea - if i alert oButton this is what I get. If I write this into the disable line it works fine. It doesnt like my oButton variable.

    monkey
    monkey - the rest is history

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    .........
    var sButtonId = (event.srcElement.id==selFrom) ? addBut : remBut;
    var oButton = document.getElementById(sButtonId);
    oButton.disabled = false;
    }
    Don't forget to id the buttons.
    What you had was being evaluated as:
    Code:
    .......
    var addBut = "cmdAddArea"
    var oButton = "cmdAddArea"
    "cmdAddArea".disabled = false; //oops!
    }
    ::: certified wild guess :::

  3. #3
    SitePoint Wizard boxhead's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    1,040
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by adios
    Code:
    .........
    var sButtonId = (event.srcElement.id==selFrom) ? addBut : remBut;
    var oButton = document.getElementById(sButtonId);
    oButton.disabled = false;
    }
    Don't forget to id the buttons.
    What you had was being evaluated as:
    Code:
    .......
    var addBut = "cmdAddArea"
    var oButton = "cmdAddArea"
    "cmdAddArea".disabled = false; //oops!
    }
    That did the trick! The trouble was the original code used addBut as the output and not as a variable.

    PS
    Is there in reason for this naming convention of starting var names with an 'o' or 's' etc?

    cheers

    monkey
    monkey - the rest is history

  4. #4
    SitePoint Addict
    Join Date
    May 2004
    Location
    Europe
    Posts
    216
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's called Hungarian Notation, the first letter indicates the type of the variable. http://msdn.microsoft.com/library/de...annotation.asp

  5. #5
    SitePoint Wizard boxhead's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    1,040
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Saturn
    It's called Hungarian Notation, the first letter indicates the type of the variable. http://msdn.microsoft.com/library/de...annotation.asp
    O I C! (although 'o' wasnt in the table, I get the idea!)

    cheers until the next problem (this is a big project!)

    monkey
    monkey - the rest is history


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
  •