I have a loginbar that can be used to login to 2 different systems depending on what value a user chooses from a dropdown. And then, I provide default values to fill each textbox depending on which login is chosen by the user. However, to make things easier for the user by clearing the default contents when the textbox receives focus, and then refilling it on blur.
$('#logintype').change(function() {
if ($(this).val() == 1) {
$('#loginf').attr('action','login1.php');
$('#loginf #user').attr('name', 'userid').attr('defaultValue', 'Username').val('Username');
$('#loginf #pass').attr('name', 'password').attr('defaultValue', 'password').val('password');
}
else {
$('#loginf').attr('action','login2.php');
$('#loginf #user').attr('name', 'email').attr('defaultValue', 'Email').val('Email');
$('#loginf #pass').attr('name', 'passed_password').attr('defaultValue', 'password').val('password');
};
});
$('.textbox').focus(function(){
if ($(this).val() == $(this).attr('defaultValue')) {
$(this).val('');
};
});
$('.textbox').blur(function(){
if ($(this).val() == '') {
$(this).val($(this).attr('defaultValue'));
};
});
Is there a more efficient way to accomplish this? I feel like I'm repeating myself and that's never a good thing. I'd also appreciate comments on whether or not this is a good idea in terms of user experience.