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:

<input value="Click here to clear text" name="nome" type="text">

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

Recommended Answers

All 11 Replies

you can use "onfocus"

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

//-->
</script>
<input type="text" name="name" value="Click here to clear text" onfocus="clearinputText();">

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

Its a simple example only

best regards
Rahul

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

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

you can use "onfocus"

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

//-->
</script>
<input type="text" name="name" value="Click here to clear text" onfocus="clearinputText();">

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:

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.

If this is a form, have you tried

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

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:

<html>
<input type="reset" value="Reset!">

</html>

this code doesn't clear textboxes

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

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

Please Try this <marquee style="font-weight: bold;scrollamount:4;scrolldenay:78;width:500;"> This code is for text moving.
by fizeRahmani India
mob: 7860734527

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.