Help on clear text in <input> !!

Thread Solved
Reply

Join Date: Jan 2006
Posts: 14
Reputation: Braga_ESI is an unknown quantity at this point 
Solved Threads: 0
Braga_ESI Braga_ESI is offline Offline
Newbie Poster

Help on clear text in <input> !!

 
0
  #1
Dec 9th, 2006
Hi,


I need help no this web page that i'm making, I think it's a bit too simple for you guys , so here goes nothing....

I need a text box like:

  1. [HTML]<input value="Click here to clear text" name="nome" type="text"> [/HTML]

That actually clears the text when you click on it...

I tried the onClick="" tag but as I looked up it´s just for buttons, right?

Hoping somebody can help me out, yours trully: Braga_ESI
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 154
Reputation: katarey is an unknown quantity at this point 
Solved Threads: 20
katarey's Avatar
katarey katarey is offline Offline
Junior Poster

Re: Help on clear text in <input> !!

 
0
  #2
Dec 9th, 2006
you can use "onfocus"

HTML and CSS Syntax (Toggle Plain Text)
  1. <script language="javascript">
  2. <!--
  3. function clearinputText() {
  4.   document.frm.name.value= "";
  5. }
  6.  
  7. //-->
  8. </script>

[HTML]<input type="text" name="name" value="Click here to clear text" onfocus="clearinputText();">[/HTML]

but this will clear the text every time when you get focus on this field,

Its a simple example only

best regards
Rahul
Freelance Web Designer & Developer
Http//www.Katarey.com
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 1,091
Reputation: MattEvans is a jewel in the rough MattEvans is a jewel in the rough MattEvans is a jewel in the rough 
Solved Threads: 63
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Veteran Poster

Re: Help on clear text in <input> !!

 
0
  #3
Dec 9th, 2006
onClick will work on most elements, onfocus is more appropriate for a text input, as tabbing to a field also counts as focus...

try:
HTML and CSS Syntax (Toggle Plain Text)
  1. <input type="text" value="Click here to clear text" onfocus="if(!this._haschanged){this.value=''};this._haschanged=true;"/>

it will only clear the text once.. i assume you want to actually put something in the text afterwards,,
Plato forgot the nullahedron..
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 14
Reputation: Braga_ESI is an unknown quantity at this point 
Solved Threads: 0
Braga_ESI Braga_ESI is offline Offline
Newbie Poster

Re: Help on clear text in <input> !!

 
0
  #4
Dec 9th, 2006
Originally Posted by MattEvans View Post
onClick will work on most elements, onfocus is more appropriate for a text input, as tabbing to a field also counts as focus...

try:
HTML and CSS Syntax (Toggle Plain Text)
  1. <input type="text" value="Click here to clear text" onfocus="if(!this._haschanged){this.value=''};this._haschanged=true;"/>

it will only clear the text once.. i assume you want to actually put something in the text afterwards,,

Thanks a lot for the help!!! My problem is solved... :lol: Sorry about my english, it's a little rustty...
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 14
Reputation: Braga_ESI is an unknown quantity at this point 
Solved Threads: 0
Braga_ESI Braga_ESI is offline Offline
Newbie Poster

Re: Help on clear text in <input> !!

 
0
  #5
Dec 9th, 2006
Originally Posted by katarey View Post
you can use "onfocus"

HTML and CSS Syntax (Toggle Plain Text)
  1. <script language="javascript">
  2. <!--
  3. function clearinputText() {
  4.   document.frm.name.value= "";
  5. }
  6.  
  7. //-->
  8. </script>

[HTML]<input type="text" name="name" value="Click here to clear text" onfocus="clearinputText();">[/HTML]

but this will clear the text every time when you get focus on this field,

Its a simple example only

best regards
Rahul

Thank you very much!!! You gave me a solution that envolves javascript that is interesting...
ho!, and sorry about my english...
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 1,091
Reputation: MattEvans is a jewel in the rough MattEvans is a jewel in the rough MattEvans is a jewel in the rough 
Solved Threads: 63
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Veteran Poster

Re: Help on clear text in <input> !!

 
0
  #6
Dec 9th, 2006
Thank you very much!!! You gave me a solution that envolves javascript that is interesting...
ho!, and sorry about my english...
mine is a javascript solution aswell, but it's all squashed into one parameter line. you could expand it to:
HTML and CSS Syntax (Toggle Plain Text)
  1. <script type="text/javascript">
  2. function checkclear(what){
  3. if(!what._haschanged){
  4. what.value=''
  5. };
  6. what._haschanged=true;
  7. }
  8. </code>
  9.  
  10. <input type="text" value="Click here to clear text" onfocus="checkclear(this)"/>

and then use "checkclear(this)" as the onfocus property for all text inputs that you want to have the same behaviour.
Plato forgot the nullahedron..
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 434
Reputation: FC Jamison is on a distinguished road 
Solved Threads: 20
Team Colleague
FC Jamison's Avatar
FC Jamison FC Jamison is offline Offline
Posting Pro in Training

Re: Help on clear text in <input> !!

 
0
  #7
Dec 10th, 2006
If this is a form, have you tried

[html]
<input type="reset" value="Reset!">
[/html]
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 1,091
Reputation: MattEvans is a jewel in the rough MattEvans is a jewel in the rough MattEvans is a jewel in the rough 
Solved Threads: 63
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Veteran Poster

Re: Help on clear text in <input> !!

 
0
  #8
Dec 10th, 2006
eeek >_< i hate those buttons!

if you've just spent umpteen minutes finding information and filling out a form; would you EVER want to reset it rather than submit it?

how about this one?

HTML and CSS Syntax (Toggle Plain Text)
  1. <input type="reset" value="Submit!">

EDIT: :lol:
Last edited by MattEvans; Dec 10th, 2006 at 3:35 am.
Plato forgot the nullahedron..
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the HTML and CSS Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC