By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,442 Members | 1,279 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,442 IT Pros & Developers. It's quick & easy.

Login box text

100+
P: 384
I have two text boxes for a login page, they have a value in them as default, when a user clicks on one of the text boxes I want the default value to disappear and if the user doesn't enter anything and clicks away I want the default value to come back but if the user enters something then that value remains in the text box.

I was thinking that the onFocus and onBlur events would be the way to do it?

Anyone any tips on how to go about this?
Jan 5 '10 #1
Share this Question
Share on Google+
2 Replies


100+
P: 384
This is the code I'm using but when I click on the username box it removes the text and when I click away from it it will add in the default text but it empties the password box, any ideas?
Expand|Select|Wrap|Line Numbers
  1. <SCRIPT TYPE="text/javascript">
  2. <!--
  3. function clearField(input,cValue) {
  4.     if(cValue == 'username' || cValue == 'password')
  5.         cValue = '';
  6.  
  7.     if(input == 1 && cValue == '')
  8.         document.login.user.value = "";
  9.     if(input == 2 && cValue == '')
  10.         document.login.pass.value = "";
  11. }
  12. function setField(input,nValue,cValue) {
  13.     if(input == 1 && cValue == '')
  14.         document.login.user.value = nValue;
  15.     if(input == 2 && cValue == '')
  16.         document.login.pass.value = nValue;
  17. }
  18. //-->
  19. </SCRIPT>
Expand|Select|Wrap|Line Numbers
  1. <input type="text" name="user" size="25" value="username" class="loginBox" onclick="clearField(1,this.value);" onBlur="setField(1,'username',this.value);" />
  2. <input type="password" name="pass" size="25" value="password" class="loginBox" onclick="clearField(2,this.value);" onBlur="setField(2,'password',this.value);" />
Jan 5 '10 #2

acoder
Expert Mod 15k+
P: 16,027
Hmm, I don't see that. Is the password text really necessary, because you can't see what it says anyway?
Jan 8 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.