For changing based upon whether the field is empty or not, you will need to establish event handlers on the text field to detect changes. The onchange handler itself will not be enough because it's not called on individual keystrokes. You'll need to also at least listen to onkeyup.

In the handler you can change the color of the background using CSS under Javascript control.

It's not foolproof however. I'm not sure how you can capture the field being emptied by a cut operation via the menu for example.