Home » » Clear form field on focus

Clear form field on focus

Written By Unknown on Senin, 20 Juni 2011 | 02.57

Hello friends. To clear a field onfocus use this simple javascript function. This is very helpful to give some default value to the field. Like search boxes contain some text for hint and removed automatically when we focus on the search box.

The javascript
 
  <script type="text/javascript">
function clearField(field){
if (field.defaultValue == field.value){
field.value = '';
}else if (field.value == '') {
field.value = field.defaultValue;
}
}
</script>


The html

  <input type="text" onFocus="clearField(this)" 
onBlur="clearField(this)" value="Default value" />


The example

Share this article :

Posting Komentar

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Kumpulan Kata Broadcast Blackberry - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger