codice:
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Esempio</title>
<script type="text/javascript">
function switchColor () {
this.style.backgroundColor = this.value === "0" ? "#ffbbbb" : "#bbbbff";
}
function addSwitches () {
for (
var
oTxtbox, nIdx = 0,
aTxtboxes = document.querySelectorAll("input[type=\"text\"]"), nLen = aTxtboxes.length;
nIdx < nLen;
nIdx++
) {
oTxtbox = aTxtboxes[nIdx];
oTxtbox.addEventListener("blur", switchColor, false);
oTxtbox.addEventListener("keyup", switchColor, false);
switchColor.call(oTxtbox);
}
}
onload = addSwitches;
</script>
</head>
<body>
<form action="test.php" method="get">
First name: <input type="text" name="firstname" />
Last name: <input type="text" name="lastname" />
Password: <input type="password" name="pwd" />
<input type="radio" name="sex" value="male" /> Male
<input type="radio" name="sex" value="female" /> Female
</p>
<input type="checkbox" name="vehicle" value="Bike" />I have a bike
<input type="checkbox" name="vehicle" value="Car" />I have a car
</p>
<input type="submit" value="Submit" />
</p>
</form>
</body>
</html>