Hi, I thought I'd share this with you. If you want all fields on a web form to be emptied of ther initial value (if any) on focus and filled again with the initial value on blur. Works with jquery.
Empty text boxes on focus if they have an initial value
$(document).ready(function () {
// saves the initial value of all text fields
$(':text').each(function () {
$(this).attr('initialvalue', $(this).val());
});
// on focus, empty the field if it has the initial value
$(":text").focus(function () {
if ( $(this).attr('initialvalue') == $(this).val() ) $(this).val('');
})
// on blur, do the reverse if the field is empty
$(":text").blur(function () {
if ($(this).val() == '') $(this).val($(this).attr('initialvalue'));
})
});
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.