|
|
change text color of an input field
A simple way to change the text within an input field is by using the oft-used style.color statement. It can be changed according to one option or many options. It is also entirely possible to make these decisions on what color to change to a part of other JavaScript functions. The coloring methods used are named colors, hex color or RGB colors. You may mix the three at any given point in the logical progression of the script. <html> <head> <script type="text/javascript"> function changeColor(color) { document.getElementById('x').style.color=color; } </script> </head> <body> <p>This example demonstrates how to change the text color of an input field.</p> <p>Mouse over the three colored table cells, and the text will change color:</p> <table width="100%"> <tr> <td bgcolor="red" onmouseover="changeColor('red')"> </td> <td bgcolor="blue" onmouseover="changeColor('blue')"> </td> <td bgcolor="green" onmouseover="changeColor('green')"> </td> </tr> </table> <form> <input id="x" type="text" value="Mouse over the colors" size="20"> </form> </body> </html> Note that this method of changing textual formatting can be applied to anywhere within the document using any valid DOM reflection of a CSS rule.
|
|