Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Very handy little script
Old 07-07-2010, 10:33 AM Very handy little script
Physicsguy's Avatar
404 - Title not found

Posts: 919
Name: Scott Kaye
Location: Ontario
Trades: 0
This script is little. But it is very useful. I use it in nearly every form I make!

Code:
onclick="javascript:this.value='';" onblur="javascript:if(this.value==''){this.value=this.getAttribute('value');}"
That's it!

It even works with password boxes, with this script:
Code:
onclick="javascript:this.value='';this.type='password';" onblur="javascript:if(this.value==''){this.value=this.getAttribute('value');this.type='text';}"
I believe the password one doesn't work with IE, though.

Simply add this to an input box with a value set, and when the user clicks on it, it will disappear, and if it's left as nothing when they deselect the box, it goes back to the original!
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!

Last edited by Physicsguy; 07-07-2010 at 10:40 AM..
Physicsguy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-07-2010, 12:48 PM Re: Very handy little script
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
I personally dont like using background images for the body..
Any page movement will fcuk up any divs above it.

I tend to create a "main" div that centred and then put all divs inside that main div.

Then add a BG to the main div and if the page moves all your divs move with it.

Just my 0.02$
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 07-07-2010, 01:55 PM Re: Very handy little script
Physicsguy's Avatar
404 - Title not found

Posts: 919
Name: Scott Kaye
Location: Ontario
Trades: 0
Umm... I think you're on the wrong thread lynxus... That made NO sense.
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
Old 07-07-2010, 07:09 PM Re: Very handy little script
logic ali's Avatar
Super Talker

Posts: 104
Trades: 0
The snag there is that if the user re-focuses the field to amend an entry, it gets deleted.

This is a common way to handle it:
Code:
<input type="text" size="30" name="uName"  value='Your name' onfocus='if( this.value == this.defaultValue ){ this.value = "";}' onblur='if( !/\S/.test( this.value ) ){ this.value = this.defaultValue; }'>
although it's better done unobtrusively:
Code:
<script type='text/javascript'>

function clearFields( formRef )
{
 var elems = formRef.elements, len = elems.length;  
 
 for( var i = 0; i < len; i++ )
  if( elems[ i ].type && /^text/.test( elems[ i ].type ) )
  {
   elems[ i ].onfocus = function(){ if( this.value == this.defaultValue ){ this.value = ""; } }
   elems[ i ].onblur = function(){ if( !/\S/.test( this.value ) ){ this.value = this.defaultValue; } }     
  }   
}

clearFields( document.getElementById( 'myForm' ) );

</script>
logic ali is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Very handy little script
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13704 seconds with 12 queries