Click to See Complete Forum and Search --> : Script Request ;)


stormrevolution
05-19-2003, 04:18 PM
Is there a script for when you click a textbox the text which was there will disapear leaving the box clear for vistors to write in!

cheers all
;)

AdamBrill
05-19-2003, 04:21 PM
You could do it like this:

<input type=text onclick="this.value='';">

But that might get annoying if they leave the box and then click on it again, since it will erase what they have already written... ;)

Jona
05-19-2003, 05:31 PM
You could also make the function run only one time, or use onMouseOver instead of onClick.

Charles
05-19-2003, 07:01 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>
<form action="">
<div>
<input value="Name" onfocus="this.value = ''" onblur="this.onfocus = function () {}">
</div>
</form>

havik
05-19-2003, 08:22 PM
I'm assuming you have default values and you wish to have this cleared once the user clicks on the text box, try this:

<script type="text/javascript">

function clearText(field) {
if(field.defaultValue == field.value)
field.value = ""
}

</script>


<input type="text" value="enter here" onfocus="clearText(this)" >


Havik