...

View Full Version : Remove help text in form field on click?!



jmansa
08-17-2009, 09:25 PM
I'm trying to figure out how to both make the text grey and when a user clicks inside a input field remove the helptext.

So far I got this:

<input onfocus="this.select()" onblur="this.value=!this.value?'E-mail here':this.value;" name="name" value="E-mail here" type="text">

What this does is allmost correct, but it doesnt remove the predefined text "E-mail here", it just select it all, and then the text is not grey...

Can somebody please guide me in the right direction...

Thanks in advance!

jmrker
08-17-2009, 09:33 PM
Without the rest of your code to view the problem in action,
you might try this:


<input onfocus="this.select()" onblur="this.value=!this.value?'':this.value;"
name="name" value="" type="text">

Amphiluke
08-17-2009, 09:35 PM
Maybe this will help you.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>Template</title>
<script type="text/javascript">
function focusMe(sender) {
if (sender.value == sender.defaultValue) {
sender.value = "";
sender.style.color = "#000000";
}
}
function blurMe(sender) {
if (sender.value == "") {
sender.value = sender.defaultValue;
sender.style.color = "#C0C0C0";
}
}
</script>
</head>
<body>
<p><input type="text" style="color: #C0C0C0;" value="E-mail here" onfocus="focusMe(this);" onblur="blurMe(this);" /></p>
</body>
</html>

P.S. jmrker was faster.

Philip M
08-17-2009, 09:37 PM
Try this:-

<input type = "text" name = "email" id = "email" value = "E-mail here:-"; style=color:'#848484';
onclick = "if (this.value == 'E-mail here:-') {this.value = '';this.style.color='#000000'}"
onblur = "if (this.value == '') {this.value = 'E-Mail here:-';this.style.color='#848484'}" >

He who posts last thinks slowest! :D:D

jmansa
08-17-2009, 10:15 PM
Try this:-

<input type = "text" name = "email" id = "email" value = "E-mail here:-"; style=color:'#848484';
onclick = "if (this.value == 'E-mail here:-') {this.value = '';this.style.color='#000000'}"
onblur = "if (this.value == '') {this.value = 'E-Mail here:-';this.style.color='#848484'}" >

He who posts last thinks slowest! :D:D

Thanks man... Did the job ;-)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum