943,746 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Dec 9th, 2006
0

Help on clear text in <input> !!

Expand Post »
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:

html Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Braga_ESI is offline Offline
14 posts
since Jan 2006
Dec 9th, 2006
0

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

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
Reputation Points: 39
Solved Threads: 23
Junior Poster
katarey is offline Offline
167 posts
since Jul 2005
Dec 9th, 2006
1

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

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,,
Moderator
Featured Poster
Reputation Points: 522
Solved Threads: 64
Veteran Poster
MattEvans is offline Offline
1,091 posts
since Jul 2006
Dec 9th, 2006
0

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

Click to Expand / Collapse  Quote originally posted by MattEvans ...
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...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Braga_ESI is offline Offline
14 posts
since Jan 2006
Dec 9th, 2006
0

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

Click to Expand / Collapse  Quote originally posted by katarey ...
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...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Braga_ESI is offline Offline
14 posts
since Jan 2006
Dec 9th, 2006
0

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

Quote ...
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.
Moderator
Featured Poster
Reputation Points: 522
Solved Threads: 64
Veteran Poster
MattEvans is offline Offline
1,091 posts
since Jul 2006
Dec 10th, 2006
0

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

If this is a form, have you tried

[html]
<input type="reset" value="Reset!">
[/html]
Team Colleague
Reputation Points: 92
Solved Threads: 21
Posting Pro in Training
FC Jamison is offline Offline
436 posts
since Jun 2004
Dec 10th, 2006
0

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

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.
Moderator
Featured Poster
Reputation Points: 522
Solved Threads: 64
Veteran Poster
MattEvans is offline Offline
1,091 posts
since Jul 2006
Mar 18th, 2010
0
Re: Help on clear text in <input> !!
<html>
<input type="reset" value="Reset!">

</html>

this code doesn't clear textboxes
Reputation Points: 10
Solved Threads: 0
Newbie Poster
k_manu12 is offline Offline
1 posts
since Mar 2010
Aug 16th, 2011
0
Re: Help on clear text in <input> !!
html Syntax (Toggle Plain Text)
  1. <html>
  2. <body>
  3. <!--Data-->
  4. <form>
  5. Full Name:
  6. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  7. <input type="text" size="30"/></br>
  8. E-mail Address:
  9. &nbsp;&nbsp;&nbsp;&nbsp;
  10. <input type="text" size="30"/></br>
  11. Password:
  12. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  13. <input type="password" size="30"/></br>
  14. Repeat Password:&nbsp;<input type="password" size="30"/></br>
  15.  
  16. <!--buttons-->
  17. <a href="regsuccess.html">
  18. <input type="submit" value="Register">
  19. </a>
  20. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  21. <input type="reset" value="Clear"/>
  22. </form>
  23.  
  24. </body>
  25. </html>

try it..
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ceasar14344 is offline Offline
1 posts
since Aug 2011

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.
Message:
Previous Thread in HTML and CSS Forum Timeline: Question about css
Next Thread in HTML and CSS Forum Timeline: displaying text and buttons in one line





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC