Handling Default Values in Form Elements (with Javascript)

You can add some fancy Javascript functionality to your forms by handling how form elements behave when a user focuses and blurs focus on different elements. When they focus on the element, this script will help you check if they have already entered content into this element or if you should clear it. When they end their focus on the element, another function will fire and check if the element has a blank element and refill it with the default value. This comes in handy when you that element is required in the form. Try it out below, focus on the first element and then focus on the next one.