954,604 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help on clear text in <input> !!

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]<input value="Click here to clear text" name="nome" type="text"> [/HTML]


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

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

Hoping somebody can help me out, yours trully: Braga_ESI

Braga_ESI
Newbie Poster
14 posts since Jan 2006
Reputation Points: 10
Solved Threads: 0
 

you can use "onfocus"

<script language="javascript">
<!--
function clearinputText() {
  document.frm.name.value= "";
}

//-->
</script>


[HTML][/HTML]

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

Its a simple example only

best regards
Rahul

katarey
Junior Poster
167 posts since Jul 2005
Reputation Points: 39
Solved Threads: 23
 

onClick will work on most elements, onfocus is more appropriate for a text input, as tabbing to a field also counts as focus...

try:

<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,,

MattEvans
Veteran Poster
Moderator
1,386 posts since Jul 2006
Reputation Points: 522
Solved Threads: 64
 

onClick will work on most elements, onfocus is more appropriate for a text input, as tabbing to a field also counts as focus...

try:

<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...

Braga_ESI
Newbie Poster
14 posts since Jan 2006
Reputation Points: 10
Solved Threads: 0
 

you can use "onfocus"

<script language="javascript">
<!--
function clearinputText() {
  document.frm.name.value= "";
}

//-->
</script>

[HTML][/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... :confused:

Braga_ESI
Newbie Poster
14 posts since Jan 2006
Reputation Points: 10
Solved Threads: 0
 
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:

<script type="text/javascript">
function checkclear(what){
if(!what._haschanged){
  what.value=''
};
what._haschanged=true;
}
</code>

<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.

MattEvans
Veteran Poster
Moderator
1,386 posts since Jul 2006
Reputation Points: 522
Solved Threads: 64
 

If this is a form, have you tried

[html]

[/html]

FC Jamison
Posting Pro in Training
Team Colleague
446 posts since Jun 2004
Reputation Points: 92
Solved Threads: 21
 

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?

<input type="reset" value="Submit!">


EDIT: :lol:

MattEvans
Veteran Poster
Moderator
1,386 posts since Jul 2006
Reputation Points: 522
Solved Threads: 64
 
k_manu12
Newbie Poster
1 post since Mar 2010
Reputation Points: 10
Solved Threads: 0
 
<html>
<body>
<!--Data-->
<form>
Full Name:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" size="30"/></br>
E-mail Address:
&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" size="30"/></br>
Password:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="password" size="30"/></br>
Repeat Password:&nbsp;<input type="password" size="30"/></br>

<!--buttons-->
<a href="regsuccess.html">
<input type="submit" value="Register">
</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" value="Clear"/>
</form>

</body>
</html>


try it..

ceasar14344
Newbie Poster
1 post since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

oh that's just the same.. thnx anyways.

elmobo
Newbie Poster
6 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

Please Try this This code is for text moving.
by fizeRahmani India
mob: 7860734527

fizerahmani123
Newbie Poster
1 post since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You