Quote:
Originally Posted by exploit
If i use tab to change the input box im using with a hidden text box will it disapear if i use onfocus ?
|
Yes, focus is independent of the method used (mouse/keyboard). When the cursor is in the text field, the field gains focus. Likewise, anchors gain focus if you tab through them or click them (you see this on the (dotted) outline some browsers add).
Quote:
Originally Posted by exploit
Also another problem with that way is you click the eliment and it makes the password box with password written in it disapear then you have to click the real password box.
Is there any way around that?
|
Yeah, of course you need to revert everything to the initial state if you “unfocus” the input (but only if nothing has been put in). The opposite of
onfocus is
onblur (or
blur() in jQuery). This is the site where I’ve done it:
http://petersohn-schuhe.de/massschaefte
Basically it works like this:
PHP Code:
$('input[type=password]')
.before($('<input>', {
type: 'text',
'class': 'password',
value: 'Password',
focus: function() {
$(this).hide().next().focus().addClass('focus');
}
}))
.blur(function() {
if($(this).val() == '') {
$(this).removeClass('focus').prev().show();
}
});
Dynamically add a text input before the password input (so it gets focus before password field when you tab through the fields). You can then position the text input above the password field. On focus it hides the text field and the password field becomes visible, gaining focus itself at the same time. And on blur it checks whether there is anything written into the password field and if not, it shows the text field again.