|
| HOMEPAGE | INDICE FORUM | REGOLAMENTO | ::. | NEI PREFERITI | .:: | RSS Forum | RSS News | NEWS web | NEWS software | |
| PUBBLICITA' | | | ARTICOLI | WIN XP | VISTA | WIN 7 | REGISTRI | SOFTWARE | MANUALI | RECENSIONI | LINUX | HUMOR | HARDWARE | DOWNLOAD | | | CERCA nel FORUM » | |
10-07-2008, 19.08.11 | #1 |
Made in Japan
Top Poster
Registrato: 04-07-2001
Messaggi: 4.461
|
[Javascript] Modificare caratteristiche testo secondo l'input
Ho una tabella con nomi di ingredienti e quantità residue. Sotto ci sono un campo di input di tipo testo e un pulsante per la conferma. La funzione deve fare questo, una volta premuto il pulsante prende il valore nel campo di input e tutti i campi della tabella sovrastante con valore nella colonna "Quantità" inferiore a tale numero devono cambiare colore, diciamo rosso. Idee su come realizzare la cosa? Mi bastano indicazioni per ora, il codice vedrò di scriverlo io. Per ora la struttura è questa 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"> <!-- function modifica(obj) { } //--> </script> </head> <body> <form name="lista" action""> <table border="0" width="auto"> <tbody> <tr> <td height="23" width="95"> <div align="left"><strong> Ingrediente </strong></div> </td> <td width="90"> <div align="left"><strong> Quantità </strong></div> </td> </tr> <tr> <td>Patate</td> <td><input type="text" value="12" name="Patate" readonly /></td> </tr> <tr> <td>Uova</td> <td><input type="text" value="32" name="Uova" readonly /></td> </tr> <tr> <td>Peperoni</td> <td><input type="text" value="8" name="Peperoni" readonly /></td> </tr> <tr> <td>Carciofi</td> <td><input type="text" value="3" name="Carciofi" readonly /></td> </tr> <tr> <td>Spaghetti</td> <td><input type="text" value="56" name="Spaghetti" readonly /></td> </tr> <tr> <td><input type="text" value="0" name="soglia" /></td> <td><input type="button" value="Modifica soglia" onclick="modifica(this)" /></td> </tr> </tbody> </table> </form> </body> </html> Edit: corretti alcuni errori nel codice. Ultima modifica di Alhazred : 11-07-2008 alle ore 00.24.13 |
11-07-2008, 01.49.31 | #2 |
Made in Japan
Top Poster
Registrato: 04-07-2001
Messaggi: 4.461
|
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"><strong>Ingrediente</strong></div></td> <td width="80"><div align="left"><strong>Quantità</strong></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> |
11-07-2008, 02.20.03 | #3 |
Made in Japan
Top Poster
Registrato: 04-07-2001
Messaggi: 4.461
|
Allora, sembra di aver capito che il confronto lo fa solo con la prima cifra dei numeri ovvero: se metto 40 il confronto viene fatto solo usando il 4, quindi 8<4 da false, tant'è vero che se come input metto 9, anche 56 diventa rosso perché 5<9...
Come si risolve questa situazione? |
11-07-2008, 02.24.12 | #4 |
Made in Japan
Top Poster
Registrato: 04-07-2001
Messaggi: 4.461
|
Vabbè, ho fatto tutto da solo
E' bastato usare parseInt() Ultima modifica di Alhazred : 11-07-2008 alle ore 02.27.31 |
Utenti attualmente attivi che stanno leggendo questa discussione: 1 (0 utenti e 1 ospiti) | |
Strumenti discussione | |
|
|
Discussioni simili | ||||
Discussione | Autore discussione | Forum | Risposte | Ultimo messaggio |
Installazione secondo HD SATA | micmen | Hardware e Overclock | 7 | 09-01-2009 16.30.11 |
Un banco si il secondo no | wilco67 | Hardware e Overclock | 2 | 07-03-2008 18.35.54 |
urgente...il prg ghost 7.0 non vede piu´ il secondo hd con immagini ghost | cippico | Software applicativo | 14 | 14-11-2005 09.11.21 |
Selezionare il testo da pagine internet fatte in Flash | LUCAB | Software applicativo | 1 | 26-10-2004 21.31.38 |
Caratteristiche PC | Anaconda | Software applicativo | 24 | 23-08-2003 03.32.44 |