Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

chagne bg color of text field that requires a value

Status
Not open for further replies.

ctenicki

Programmer
May 13, 2002
10
US
i was wondering how i might change the color of a select box or text field that are required fields after a submit has run a valitdator script and found that there still exists some null values. so basically it would color the fields that the users still needs to enter a value in after a submit has been tried.
thanks for any ideas
 
This is what I use:
Code:
<HTML>
<HEAD>

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!--

function color(changecolor, bg) {
  if (changecolor.style) changecolor.style.backgroundColor = bg;
}

function Input(form) {
  var bg1 = &quot;#ccc000&quot;;
  var bg2 = &quot;white&quot;;
  var valid = true;
  if (form.first.value == &quot;&quot;) {
    valid = false;
    color(form.first, bg1);
  } else {
      color(form.first, bg2);
  }
  if (form.last.value == &quot;&quot;) {
    valid = false;
    color(form.last, bg1);
  } else {
     color(form.last, bg2);
  }
  if (!valid) alert(&quot;Please fill the form out.&quot;);

  return valid;
}

// -->
</SCRIPT>

<body bgcolor=&quot;#000000&quot; text=&quot;bda94c&quot;>
<FORM onSubmit=&quot;return Input(this)&quot;>
  <table border=&quot;0&quot;>
    <tr> 
      <td valign=&quot;top&quot;> 
        <p><font size=&quot;2&quot; face=&quot;Arial, Tahoma, Verdana&quot;>Validates the First and 
          Last name.  <br>
          <i>In IE, the textbox color changes to indicate field is blank, as well 
          as a alert pops up.  <br>
          In NS, a alert pops up.</i></font></p>
        <p> </p>
      </td>
    </tr>
    <tr> 
      <td>First name: 
        <input type=&quot;text&quot; name=&quot;first&quot; size=&quot;20&quot; value=&quot;&quot;>
      </td>
    </tr>
    <tr> 
      <td>Last name: 
        <input type=&quot;text&quot; name=&quot;last&quot; size=&quot;20&quot; value=&quot;&quot;>
      </td>
    </tr>
    <tr> 
      <td>
        <input type=&quot;submit&quot; value=&quot;send&quot; name=&quot;submit&quot;>
      </td>
    </tr>
  </table>
  </FORM>
</BODY>
</HTML>
Hope it helps ya... I have not failed; I merely found 100,000 different ways of not succeding...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top