faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

45 of 54 people (83%) answered Yes
Recently 5 of 10 people (50%) answered Yes

Entry

How do I dynamically change the style of a form element in both NN & IE

Apr 4th, 2008 19:52
ha mo, Tony Crosby, tony hancock,


Say you have a field,
<input type="text" name="MyField" class="Input_Type1">
 You could change the class name with javascript liek so:
<script>
document.getElementById('MyField').className="Input_Type2";
</script>
 This method would require the style calls in the head of your document.
<style>
.Input_Type1 {border:1px #50555A solid; background:#EEEEEE; font:12px
.Input_Type2 {border:1px #000000 solid; background:#FFFFFF; font:12px
</style>
 Or, you could access the style elements directly,
<input type="text" name="MyField" style="border:1px #50555A solid; 
background:#EEEEEE; font:12px">
<script>
document.getElementById('MyField').style.background='FFFFFF';
</script>
 Just replace MyField with the name of the form field you want to 
manipulate and "backgound" with the style element you want to change. 
Not to mention changing "FFFFFF" to the desired value of the style 
element.
 Tony (Crosby)
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com