Ciao Ragazzi. Ho un problemino con .toLowerString e .toUpperString.
Nell'esercizio devo prendere una stringa da un form/input e devo invertire i caratteri da maiuscolo a minuscolo, e viceversa.
Il problema è che l'assegnazione nella variabile del carattere convertito non funziona!
Questo è il codice:
codice:<html> <head> <script language="javascript"> function invertCase(text1) { var testo = document.form1.text1.value; for (i=0; i<testo.length; i++) { if (testo[i] == testo[i].toLowerCase()) { alert("Inverto " + testo[i] + " in " + testo[i].toUpperCase()); testo[i] = testo[i].toUpperCase(); //questo non funziona! } else if (testo[i] == testo[i].toUpperCase()) { alert("Inverto " + testo[i] + " in " + testo[i].toLowerCase()); testo[i] = testo[i].toLowerCase(); //e manco questo! } } alert("Testo invertito: " + testo + " " +testo.length); } </script> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <form name="form1"> <input type="button" value="Inverti!" onClick="invertCase(text1)"> <input type="text" name="text1" size="32"/> </form> <div>Sciao</div> </body> </html>