Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jan 2005
    Posts
    470
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Changing form class attribute

    Suppose I have the following to be submitted to a PHP script:
    Code:
    <form name="input_form" action="submit.php" method="POST">
    <input type="text" name="text_input[name]" size="20" class="DarkGray" />
    </form>
    How could I use JavaScript to change the value of the class attribute to "LightGray" onFocus? I have tried a number of ways but nothing seems work.

    I have tried searching for a way to directly change the class using Google but have only found exampes that change the style instead of simply changing the class.

    Currently I'm using the following:
    Code:
    onFocus="document.forms['input_form']['text_input[name]'].class='LightGray'"
    I've also tried:
    Code:
    onFocus="this.class='LightGray'"
    Last edited by bauhsoj; 08-20-2005 at 01:49 AM.

  • #2
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Code:
    onFocus="document.forms['input_form']['text_input[name]'].className='LightGray'"
    Hope this helps.

    m_n
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #3
    Regular Coder
    Join Date
    Jan 2005
    Posts
    470
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks! That did the trick perfectly!

    Odd though, that it isn't included in the DOM at W3CSchools.
    http://www.w3schools.com/htmldom/default.asp
    Last edited by bauhsoj; 08-20-2005 at 06:53 PM.

  • #4
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #5
    Regular Coder
    Join Date
    Jan 2005
    Posts
    470
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Wow, that is exactly what I needed!


  •  

    Posting Permissions

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