NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page How do I grey out the default text of a text box?

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
6 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 10-03-2011, 09:02 PM THREAD STARTER               #1 (permalink)
dkr
Respect My Authority!
Join Date: Jul 2005
Location: Canada
Posts: 2,234
dkr has a brilliant futuredkr has a brilliant futuredkr has a brilliant futuredkr has a brilliant futuredkr has a brilliant futuredkr has a brilliant futuredkr has a brilliant futuredkr has a brilliant futuredkr has a brilliant futuredkr has a brilliant futuredkr has a brilliant future
 



Save The Children Baby Health

How do I grey out the default text of a text box?


Hey there,

I have a text box that shows some default text. On mouseover, the text would disappear and the user would be able to type in there regularly:
http://snpr.cm/bnGelO.jpg

However, I'd like to apply some CSS styling to the default text so that it looks like instructional text and nothing else. Do you have any ideas on how to accomplish this?

1) Default text would be grey colored
2) Onmouseover the text would disappear, and when the user starts typing it would be just regular black.

Here's the current code for this:

HTML Code:
<textarea class="textarea" onblur="if(this.value=='') this.value='Question or topic you need help with (in one sentence)...';" onfocus="if(this.value=='Question or topic you need help with (in one sentence)...') this.value='';" id="question" name="question">Question or topic you need help with (in one sentence)...</textarea>
Thanks!
????: NamePros.com http://www.namepros.com/programming/732951-how-do-i-grey-out-default.html
Donny
__________________
Follow Me (new!): @donnyouyang
Founder @ Rayku | Kinkarso Tech
dkr is offline  
Old 10-04-2011, 05:03 AM   #2 (permalink)
NamePros Member
Join Date: Feb 2011
Posts: 43
brackwho is an unknown quantity at this point
 



Quick, and maybe not compatible with old browsers...

#question {background:url(your image url) no-repeat top left;color:black}
#question:hover {background:white}
#question:focus {background:white}

Just create a image of your "instructional text" and use it as a background.
__________________
my blog
brackwho is offline  
Old 10-05-2011, 05:10 AM   #3 (permalink)
 
BillyConnite's Avatar
Join Date: Jul 2005
Location: Coffs H, Australia
Posts: 3,456
BillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond repute
 


Wildlife Parkinson's Disease Parkinson's Disease
Hi dkr,

I have done this before using italics and grey text to represent instructional text, and then js to change the css properties. Seems to work quite well.

I've coded a html page so you can see for yourself. Take what you need if this is where you wanted, adjust the font and colors etc to suit your current site.

Please note that you did not have opening and closing brackets for your javascript if conditions, this is fine for single operations however now that there are multiple operations i've added them in, otherwise the script won't work the way you want. Also, note i have used the general 'font' property to adjust the italics instead of 'font-style' as javascript will error on using a dash in there.
Code:
<html>
<head>
<title>Testing textbox css change</title>
<style type="text/css">
#question
{
color:grey;
font: italic 12pt Arial;
}
</style>
</head>
<body>
<textarea class="textarea" onblur="if(this.value=='') { this.value='Question or topic you need help with (in one sentence)...'; this.style.color='grey'; this.style.font='italic 12pt Arial'; }" onfocus="if(this.value=='Question or topic you need help with (in one sentence)...') { this.value=''; this.style.color='#111111'; this.style.font='normal 12pt Arial'; }" id="question" name="question">Question or topic you need help with (in one sentence)...</textarea>
</body>
</html>
You can see a demo here: http://thisisaserver.com/thisisafold...onal-text.html
????: NamePros.com http://www.namepros.com/showthread.php?t=732951

You can easily edit it if you'd rather the text disappear on mouseover, however i prefer to make people click before the text disappears to ensure they have read it.

Hope this helps, let me know,
Rhett.
Last edited by BillyConnite; 10-05-2011 at 05:15 AM.
BillyConnite is offline  
Old 10-06-2011, 03:19 PM THREAD STARTER               #4 (permalink)
dkr
Respect My Authority!
Join Date: Jul 2005
Location: Canada
Posts: 2,234
dkr has a brilliant futuredkr has a brilliant futuredkr has a brilliant futuredkr has a brilliant futuredkr has a brilliant futuredkr has a brilliant futuredkr has a brilliant futuredkr has a brilliant futuredkr has a brilliant futuredkr has a brilliant futuredkr has a brilliant future
 



Save The Children Baby Health
This worked brilliantly, thanks a million!
__________________
Follow Me (new!): @donnyouyang
Founder @ Rayku | Kinkarso Tech
dkr is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need quick fix ''SQL'' wordtubepress Programming 5 06-27-2011 01:19 PM
MSN scammer!! offers you to be a moderator, don't give personal data! Jim_Westergren Warnings & Alerts 54 07-05-2006 06:35 PM
Googlism - What does google think of you? deadserious The Break Room 55 12-15-2005 09:09 AM
Xbox 360 hype andriegel Domain Name Discussion 5 05-18-2005 11:46 AM

 
All times are GMT -7. The time now is 02:49 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger