Ho provato a fare qualcosa e mi è venuto fuori questo, ma non funziona correttamente.
Ad esempio se si mette come input 40, i numeri 12, 32 e 3 diventano rossi, ma l'8 no, nonostante con un alert abbia visto che l'if controlla la disuguaglianza 8<40 che deve dare true, invece no, non esegue l'istruzione prevista dal true.
Da cosa dipende?
codice:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Evidenzia soglia</title>
<script type="text/javascript">
<!--
var ingredienti = new Array("Patate","Uova","Peperoni","Carciofi","Spaghetti");
function evidenzia(obj)
{
var i = 0;
for(i = 0; i < ingredienti.length; i++)
if(obj.form.elements[ingredienti[i]].value < obj.form.soglia.value)
document.getElementById(ingredienti[i]).style.color = "#FF0000";
else
document.getElementById(ingredienti[i]).style.color = "#000000";
}
//-->
</script>
</head>
<body>
<form name="lista" action="">
<table border="0" width="175">
<tbody>
<tr>
<td height="23" width="95"><div align="left">Ingrediente</div></td>
<td width="80"><div align="left">Quantità</div></td>
</tr>
<tr>
<td>Patate</td>
<td><input type="text" value="12" name="Patate" id="Patate" size="4" readonly /></td>
</tr>
<tr>
<td>Uova</td>
<td><input type="text" value="32" name="Uova" id="Uova" size="4" readonly /></td>
</tr>
<tr>
<td>Peperoni</td>
<td><input type="text" value="8" name="Peperoni" id="Peperoni" size="4" readonly /></td>
</tr>
<tr>
<td>Carciofi</td>
<td><input type="text" value="3" name="Carciofi" id="Carciofi" size="4" readonly /></td>
</tr>
<tr>
<td>Spaghetti</td>
<td><input type="text" value="56" name="Spaghetti" id="Spaghetti" size="4" readonly /></td>
</tr>
<tr>
<td><input type="text" value="0" name="soglia" size="4" /></td>
<td><input type="button" name="Controlla" value="Controlla" onclick="evidenzia(this)" /></td>
</tr>
</tbody>
</table>
</form>
</body>
</html>