#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Posts
    28
    Rep Power
    0

    Question Using JavaScript to update a input text fields background colour using CSS.


    Hi

    I am having ptoblems to use JavaScript to update a input text fields background colour using CSS. I am trying to disable the box and change the background color this is so that the user can see it's disabled.

    Any suggestions.

    Regards
    Rudi
    Last edited by rudidebruyn; December 17th, 2002 at 06:51 AM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Nov 2001
    Posts
    1,882
    Rep Power
    19
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <script>
    function disable(el)
    {
    if (document.getElementById('myCheckBox').checked) {
    document.getElementById(el).disabled = true;
    document.getElementById(el).style.backgroundColor = 'red';
    }
    else {
    document.getElementById(el).disabled = false;
    document.getElementById(el).style.backgroundColor = '';
    }
    }
    </script>
    </head>
    
    <body>
    <form name="form1" id="form1" method="post" action="">
      <p>
        <input type="checkbox" name="myCheckBox" id="myCheckBox" value="checkbox" onclick="disable('myTextBox')" />
        Disable TextBox</p>
      <p> 
        <input type="text" name="myTextBox" id="myTextBox" />
      </p>
    </form>
    </body>
    </html>
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Posts
    28
    Rep Power
    0

    Thumbs up Greate!!!


    degsy,

    Spot On! Thanks a million!

    Rudi

IMN logo majestic logo threadwatch logo seochat tools logo