Click to See Complete Forum and Search --> : textbox


NZ_Kiwis
03-17-2006, 01:54 AM
this is a blank textbox, some websites have a thing inside like "username" and when you click in there is goes away... how can i add this anyone know??



<input name='username' size='10' style='font-family: Tahoma; border-style: solid; border-width: 1px; font-size:8pt'>


PS: i know this is not PHP but it's the only website i use a forum on and everyone is so good at helping ;-)

laserlight
03-17-2006, 02:04 AM
tsk tsk, but anyway, add the attribute:
onfocus="this.value=''"

That reminds me, we actually have a ClientSide Technologies (http://phpbuilder.com/board/forumdisplay.php?f=27) forum that you should have used.

NZ_Kiwis
03-17-2006, 02:16 AM
that only works when you click in the box. i want to show when the page loads :-)

Weedpacket
03-17-2006, 02:23 AM
PS: i know this is not PHP but it's the only website i use a forum on and everyone is so good at helping ;-)Which is one reason why there is now a more appropriate forum for these sorts of questions.

Anyway;
that only works when you click in the box. i want to show when the page loads :-)onLoad="" then.

dream.scape
03-17-2006, 08:13 AM
that only works when you click in the box. i want to show when the page loads :-)

no you don't put the value you want in there; that is used to clear it out. You put the default value in the value="" attribute.

<input name="search" value="search for..." onfocus="this.value='';" />

Merve
03-17-2006, 11:35 AM
Maybe I'm wrong, but I see an issue with simply using onfocus. If the user types a value in the textbox, clicks somewhere else, then clicks back in the textbox, whatever value he or she had typed in the textbox would be erased. You would need some sort of check to make sure it was only the first focus.

How about:
<script>
var isFocus = 1;

function eraseText () {
if(isFocus == 1) {
window.document.blahform.blahtext.value = "";
var isFocus = 0;
}
}
</script>

<form name="blahform" id="blahform" action="#">
<input type="text" name="blahtext" id="blahtext" value="Type Here!" onfocus="eraseText();" />
</form>

I apologize for my malformed JavaScript and the fact that I may have made a few mistakes in the code, but that's the general idea of what you should have.

NZ_Kiwis
03-17-2006, 01:21 PM
so would this not work as well then??

onfocus=this.type='password'

JPnyc
03-17-2006, 02:16 PM
If you put proper quotes around it, it would

NZ_Kiwis
03-17-2006, 02:25 PM
such as?

JPnyc
03-17-2006, 02:55 PM
onfocus="this.type='password';"

Merve
03-17-2006, 05:25 PM
so would this not work as well then??

onfocus=this.type='password'

In that case, only the code that JPnyc provided is necessary. That's because no matter how many times the input box is focused, you want it to change to a password input the first time, and remain a password input on subsequent focuses.

The problem with only using onfocus with the previous case (username) is that you don't want their username to disappear if they unfocus the textbox and them refocus it.