I have a pretty standard html form with a few input boxes. I have a small div under each textbox that displays directions when the textbox has focus (the rest of the time they are hidden). The divs can also change color and display error messages.
I would like to be able to have one javascript function to show directions on focus, one function to show errors on blur, one function to hide directions/errors etc.
The problem that I am running into is how to best associate the textboxes and their respective divs. I have used a naming convention in which I gave the textboxes an ID like field1
and then called their div field1Div
. This worked OK but something tells me there is a better way to do this.
What is the "correct" way to associate the div and textbox?