Toggles instructional and default copy text and styles


/ Published in: JavaScript
Save to your folder(s)

This utility function attaches listeners to a text field or text area. It supports default text for instructional copy. The original text in the field is used as the instructional/default text. When the box gets focus, it disappears and the user can type. If the focus is lost and the box is empty, the original text will be placed again.

The method also swaps CSS class if the class names are passes as arguments. There is one class for default text, and one for user text.
This is optional.

Usage:
Create a text field in HTML. For example, use parameters:

input type="text" id="t1" class="textFieldDefault iCopy" value="Type something here"

Then in script block:

sl_addClearCopyListeners(document.getElementById("t1"), 'iCopy' , 'noCopy');

// or without CSS classes:
sl_addClearCopyListeners(document.getElementById("t1"));
'noCopy');

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.