Originariamente inviato da Symon83
Ciao ragazzi, ho un form con un campo testo e uno password, vorrei far si che dentro il campo in cui si scrive compaia la scritta ''user'' e ''password'' nel secondo, nel primo caso mi basta mettere nel value="user"
ma nel secondo come posso fare? vorrei che quando un utente ci clicca dentro sparisse la scritta predefinita in modo da poter inserire lui i suoi dati. Chi può aiutarmi? Grazie Simone
No! Non è vero che basta mettere user nel value, ci vuole javascript.
Io conosco solo questo modo, vedi tu!
codice:
<!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>Documento senza titolo</title>
<script language="javascript" type="text/javascript">
function delDefaultValue(elem) {
elemChange = document.getElementById(elem);
if (elemChange.value == elemChange.defaultValue)
{
elemChange.value='';
}
elemChange.style.color = '#000';
}
function checkEmptyValue(elem) {
elemChange = document.getElementById(elem);
if (elemChange.value == '')
{
elemChange.style.color = '#bbb';
elemChange.value = elemChange.defaultValue;
}
}
</script>
</head>
<body>
<form action="" method="post" enctype="text/plain" name="mioForm" target="_self">
<input
type="text"
id="user" name="user"
value="UserName"
onfocus="delDefaultValue('user')"
onblur="checkEmptyValue('user')"
style="color: #bbb" />
<input
type="password"
id="Pasword" name="Password"
value="Password"
onfocus="delDefaultValue('Password')"
onblur="checkEmptyValue('Password')"
style="color: #bbb" />
</form>
</body>
</html>