l'ho preso dal sorgente pagina.
Mi ha interessato perchè fa uso della proprietà defaultValue che proprio non ricordavo.
Ho leggermente cambiato per evitare di inserire spazi bianchi
Ma è chiaro che il principio di funzionamento è lo stesso.
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>
<title>Pagina senza titolo</title>
<script language="javascript" type="text/javascript">
// <!CDATA[
function autoClear(obj)
{
if(obj.value == obj.defaultValue)
{
obj.value = '';
}
}
function autoRestore(obj)
{
if(trim1(obj.value) == '')
{
obj.value = obj.defaultValue;
}
}
//-------------------------------------------------------------------
// rimuove gli spazi iniziali e finali da strValore
//-------------------------------------------------------------------
function trim1(stringa)
{
stringa = stringa + "";
return stringa.replace(/^ */,"").replace(/ *$/,"");
}
// ]]>
</script>
</head>
<body >
<input type="text" name="cm-19807-19807" id="email-newsletter" value="Your email" onfocus="autoClear(this); " onblur="autoRestore(this); " title="Enter your email" />
</body>
</html>