form input type="text" has value onload, clear onc
Moderator: General Moderators
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
form input type="text" has value onload, clear onc
Does anyone know the little snippet code which allows you to put a value in the form text box and password box onload but when a user clicks in the box the text disappears?
Thanks
Thanks
-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA
Code: Select all
onClick=formName.inputName.value = "";- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
alternately, you could dynamically change it's css background-image attribute maybe, if you are requiring newer browsers.. but you'll need to be careful, netscape and ie display background-image very differently..
best option is just having that text written nearby those fields.
best option is just having that text written nearby those fields.
Last edited by feyd on Tue Apr 20, 2004 7:14 pm, edited 1 time in total.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
"type" is a read-only attribute in javascript, that's why you can't change it through script. the background-image idea would work, but then you have to have an image of the passwords. that sounds like ick.
I have the following functions that swap out one field for another in the same position.
function swapThem(trigger,source,replacement)
{
hide(source);
show(replacement);
}
function show(elm)
{
if (document.getElementById && document.getElementById(elm) != null)
{
document.getElementById(elm).style.display='block';
}
}
function hide(elm)
{
if (document.getElementById && document.getElementById(elm) != null)
{
document.getElementById(elm).style.display='none';
}
}
Just have the two fields next to each other. You could trigger it like:
<input type="text" id="password_txt" onclick="swapThem(this,'password');" />
<input type="password" id="password" />
I have the following functions that swap out one field for another in the same position.
function swapThem(trigger,source,replacement)
{
hide(source);
show(replacement);
}
function show(elm)
{
if (document.getElementById && document.getElementById(elm) != null)
{
document.getElementById(elm).style.display='block';
}
}
function hide(elm)
{
if (document.getElementById && document.getElementById(elm) != null)
{
document.getElementById(elm).style.display='none';
}
}
Just have the two fields next to each other. You could trigger it like:
<input type="text" id="password_txt" onclick="swapThem(this,'password');" />
<input type="password" id="password" />
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
feyd, the onClick idea you gave me works even better if you use onFocus instead of onClick since in explorer using the "tab" key to navigate through the form does not clear the value if onClick is used. Thanks for letting me know what the code was to change the value 
Unipus, it's ok about using your swapping idea. I'm just gonna keep it as a password box with masked characters in it. Thanks anyway. The code may come useful somewhere else some time.
Unipus, it's ok about using your swapping idea. I'm just gonna keep it as a password box with masked characters in it. Thanks anyway. The code may come useful somewhere else some time.