Reputation: 20765
Is there a simple way to get text such as "Please start typing to search" with Autocomplete on jQueryUI?
I didn't find anything in the options for the widget that does this automatically.
Upvotes: 0
Views: 2533
Reputation: 1382
Implementing watermark can lead to lot of manual work and most of your code may need re work depending upon business logic.
Try to go for the jquery watermark plugin. Here this will give you a head start, include this:
<script type="text/javascript" src="http://labs.mario.ec/jq-watermark/jquery.watermark.js"></script>
and add this event handler
$(document).ready(function () {
$('idOfTextBox').watermark('Please enter', {
className: 'lightText'
});
});
Specify the css style class name
.lightText{
//whatever color
}
Upvotes: 1
Reputation: 770
updated add
value="Please start typing"
to the input tag. You also might want to add an onclick to the input to clear the text when you click on it i.e.
$('#searchBox').click(function(){
if( $(this).val() == 'Please start typing'){
$(this).val('');
}
});
here is a slight improvement if you only want it to be called the first time:
var watermark = 'please start typing';
var searchBox;
function setWatermark(){
searchBox = $('#searchBox');
searchBox.val( watermark );
searchBox.bind('click',clearWatermark);
}
function clearWatermark(){
if( $(this).val() == watermark){
$(this).val('');
searchBox.unbind('click',clearWatermark);
}
}
$(document).ready(function(){
setWatermark();
});
Upvotes: 1
Reputation: 1741
What about using
autocomplete( "result", handler )
and getting that text with a function 'handler'?
Upvotes: 0