Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

clear default text onClick - restore if nothing entered (See related posts)

From ScriptyGoddess:
http://www.scriptygoddess.com/archives/2005/11/15/clear-default-text-onclick-restore-if-nothing-entered/

In your document's head:
<script type="text/javascript">
function clickclear(thisfield, defaulttext) {
if (thisfield.value == defaulttext) {
thisfield.value = "";
}
}
function clickrecall(thisfield, defaulttext) {
if (thisfield.value == "") {
thisfield.value = defaulttext;
}
}
script>


The actual form field:
<input type="text" name="myfield" onclick="clickclear(this, 'default text')" onblur="clickrecall(this,'default text')" />

You need to create an account or log in to post comments to this site.


Related Posts