Remove the Value of an Inputbox on Click/Focus
this is a jquery Snippet
This can sometimes be very nice when you have small space (perhaps you're writing a page for mobile devices) and you can't waste space for an input's field descriptionThe solution is to put the description inside the inputfield like this:
But when the user has to manually remove the value it would suck.. so use my code:
$(document).ready(function(){
$('.removeOnFocus').each(function()
{
this.data = new Object(); //TODO don't overwrite previous data
this.data.value = this.value;
$(this).focus(function(){
if (this.value == this.data.value)
this.value = '';
});
$(this).blur(function(){
if (this.value == '')
this.value = this.data.value;
});
});
});
Example
A small example where it can be usedHere is the Code:
<input type="text" name="name" value="Name" class="removeOnFocus" style="width:100px"/>
<input type="text" name="email" value="Email" class="removeOnFocus" style="width:100px"/><br/>
<textarea class="removeOnFocus" style="width:210px;height:120px">Enter your comment here..</textarea>