Return to Snippet

Revision: 5438
at March 9, 2008 08:04 by gbot

Initial Code
// form input prefill clear on focus, and reset on blur (if empty)

function prefillClear(field) {

if (field.defaultValue==field.value) {field.value = '';}

else if (field.value == '') {field.value = field.defaultValue;}


// usage

<input type="text" name="input1" value="Enter your data" onfocus="prefillClear(this);" onblur="prefillClear(this);" />

// suggest using some further javascript to parse all input fields and apply these functions on domReady. This would save having to put the function calls inline.

Initial URL

Initial Description

Initial Title
form input prefill clearer and reset

Initial Tags

Initial Language