View Full Version : form feild value's
geoffb
10-15-2006, 09:08 PM
Evening all.
Im in the proccess of building a form for a site, and would like to know how to make the initial valus dissapear when a user goes to submit text into each box.
Ie: the name box has 'name' in it but at the mo i have to delete it before filling in details.
Many of you may wonder why i'm not using <label for=""> to place outside the text areas, and although I have used these on previous sites im after something different on this one.
Please advise.
geoffb
the-disturbed
10-16-2006, 09:43 PM
first thing that comes to mind for me is javascript, essentially the same idea as what i have on my site for my buttons:
in the html define the default value, then use onmouseover to run a javascript that will turn the default value into ""
i'll get u some code, when i get home, assuming this works lol, just a theory
mwinter
10-16-2006, 11:55 PM
Im in the proccess of building a form for a site, and would like to know how to make the initial valus dissapear when a user goes to submit text into each box.
One can alter the value of a control when it receives focus, but it's not usually a good idea. Playing with input like that can just confuse the visitor - not everyone may understand why a value just disappeared.
Many of you may wonder why i'm not using <label for=""> to place outside the text areas, and although I have used these on previous sites im after something different on this one.
Before you continue, ask yourself: if the value that presumably indicates the purpose of that control is gone, will the visitor still understand, upon reviewing the form, what each of the given responses where meant to represent? If it is not abundantly clear, I would urge you not to pursue this.
function clearDefault(control) {
if (control.value == control.defaultValue) control.value = '';
}
<input type="text" value="..." onfocus="clearDefault(this);">
You may need to be careful here to ensure that the visitor would not want to use the default value as their response.
Mike
zuguz
10-18-2006, 11:06 PM
I've done it even in a simpler way
<input value="BLABLABLA" type="text" id="username" onFocus="if (this.value == 'BLABLABLA') this.value = 'whateverer you want here';">
et voilá....everytime it is with 'default' value it changes to '<whatever_you_want_even_nothing_if_you_want_to>'
if you need something else.....i think it's a easy turnaround from this point
/*
if(if.needed == false)
remove(if);
*/ (LOOOL)
BIG UP
zuguz :)
mwinter
10-19-2006, 12:48 PM
I've done it even in a simpler way
Not to dash your enthusiasm, but how is what you've posted simpler? It would seem that the OP intends to do this with several controls, which would mean code duplication with your approach. It may also require maintainence: if the default value changes, the event listener will also need to be changed.
Mike
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.