Change color of form Components

[Total: 0    Average: 0/5]

This sets the colors of the form components using the style properties.

Body Code:

<form name=exf1>
<input style="color:#000440;background-color:#d0d0d0;" type=text name=t1 value="text value">
<BR>
<input type=text readonly value=false name=toggle>
<BR>
<input type=button name=b1 value="Click Me" onclick="doIt()">
<BR>
<input type=button name=b2 value="Click Me" onclick="doThat()">
</form>
<script>
var toggle=false;
function doIt()
{
  if(toggle)
  {
    document.exf1.t1.style.color="green";
    document.exf1.t1.style.backgroundColor="orange";
  }
  else
  {
    document.exf1.t1.style.color="#000440";
    document.exf1.t1.style.backgroundColor="#d0d0d0";
  }
  document.exf1.toggle.value=toggle=!toggle;
}
function doThat()
{
  document.exf1.b1.style.color="gold";
  document.exf1.b1.style.backgroundColor="red";
}
</script>

Times Viewed: 1

Leave a Reply

Your email address will not be published. Required fields are marked *