...

View Full Version : Changing form class attribute



bauhsoj
08-20-2005, 01:13 AM
Suppose I have the following to be submitted to a PHP script:

<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:
onFocus="document.forms['input_form']['text_input[name]'].class='LightGray'"

I've also tried:
onFocus="this.class='LightGray'"

martin_narg
08-20-2005, 02:26 AM
onFocus="document.forms['input_form']['text_input[name]'].className='LightGray'"


Hope this helps.

m_n

bauhsoj
08-20-2005, 06:51 PM
Thanks! That did the trick perfectly! :thumbsup:

Odd though, that it isn't included in the DOM at W3CSchools.
http://www.w3schools.com/htmldom/default.asp

martin_narg
08-20-2005, 11:33 PM
Gecko:
http://www.mozilla.org/docs/dom/domref/dom_el_ref4.html#1027595

IE:
http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/classname.asp

Hope this helps

m_n

bauhsoj
08-21-2005, 01:26 AM
Wow, that is exactly what I needed! :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum