|
| 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 » | |
21-07-2008, 20.08.26 | #1 |
Made in Japan
Top Poster
Registrato: 04-07-2001
Messaggi: 4.461
|
[JSP] Limitare testo in una textarea
[html] <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <center> <h2>Crea Ricetta</h2><br><br> Preparazione ricetta <form> <table width="400" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <td width="auto" height="275"> <table width="100%" border="0" cellpadding="1" cellspacing="5"> <tr> <td colspan="2"><textarea name="preparazione" rows="6" cols="50"></textarea> </td> </tr> <tr> <td>Nome ricetta</td> <td><input type="text" name="nome" maxlength="40"/></td> </tr> <tr> <td>Tipo di portata</td> <td><select name="tipo" size="1"> <option value="primo">Primo</option> <option value="secondo">Secondo</option> <option value="dolce">Dolce</option> </select> </td> </tr> <tr> <td>Difficoltà</td> <td><select name="tipo" size="1"> <option value="facile">Facile</option> <option value="media">Media</option> <option value="difficile">Difficile</option> </select> </td> </tr> <tr> <td>Tempo di preparazione</td> <td><input type="text" name="tempo" size="5"/> minuti</td> </tr> <tr> <td>Ingredienti Principali</td> <td><select name="Ingrediente1" size="1"> <option value="facile">Merluzzo</option> <option value="media">Pomodoro</option> <option value="difficile">Fusilli</option> </select> <select name="Ingrediente2" size="1"> <option value="facile">Merluzzo</option> <option value="media">Pomodoro</option> <option value="difficile">Fusilli</option> </select> <select name="Ingrediente3" size="1"> <option value="facile">Merluzzo</option> <option value="media">Pomodoro</option> <option value="difficile">Fusilli</option> </select> </td> </tr> <tr><td> </td><td> </td></tr> <tr> <td></td> <td><input type="submit" name="submit" value="Inserisci ricetta" /></td> </tr> </table></td> </tr> </table> </form> <br> <a href="errorericetta.html">Errore</a> </center> </body> </html> [/html] Vorrei che nella textarea sia possibile inserire massimo 1000 caratteri ma non ci riesco. Ho provato alcune soluzioni trovate cercando con google, ma non mi funzionano. Come posso fare? |
22-07-2008, 09.14.10 | #2 |
Hero Member
Registrato: 14-01-2005
Loc.: Rome, Italy
Messaggi: 1.132
|
é un po datato ma funziona ancora
[HTML] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Limitare caratteri in una textarea</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script type="text/javascript"> var ns6=document.getElementById&&!document.all function restrictinput(maxlength,e,placeholder){ if (window.event&&event.srcElement.value.length>=maxl ength) return false else if (e.target&&e.target==eval(placeholder)&&e.target.v alue.length>=maxlength){ var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys if (pressedkey.test(String.fromCharCode(e.which))) e.stopPropagation() } } function countlimit(maxlength,e,placeholder){ var theform=eval(placeholder) var lengthleft=maxlength-theform.value.length var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder) if (window.event||e.target&&e.target==eval(placeholde r)){ if (lengthleft<0) theform.value=theform.value.substring(0,maxlength) placeholderobj.innerHTML=lengthleft } } function displaylimit(thename, theid, thelimit){ var theform=theid!=""? document.getElementById(theid) : thename var limit_text='<b>Puoi inserire ancora <span id="'+theform.toString()+'">'+thelimit+'</span> caratteri</b>' if (document.all||ns6) document.write(limit_text) if (document.all){ eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)} eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)} } else if (ns6){ document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true); document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true); } } </script> </head> <body> <h1>Limitare i caratteri in una textarea</h1> <form name="modulo"> <p> <textarea name="commenti" id="commenti" cols=25 rows=15></textarea><br> <script> displaylimit("","commenti",50) </script> </form> </body> </html> [/HTML]
___________________________________
♫ m u s i c ♪ i s ♫ t h e ♪ a n s w e r ♫ "Il più piccolo dei piccoli felini è già lui stesso un vero capolavoro". (Leonardo da Vinci) Namasté! |
22-07-2008, 09.36.11 | #3 |
Made in Japan
Top Poster
Registrato: 04-07-2001
Messaggi: 4.461
|
Ho risolto con questa funzione javascript
Codice:
function textCounter(field, countfield, maxlimit) { if (field.value.length > maxlimit) // se sono stati scritti troppi caratteri field.value = field.value.substring(0, maxlimit); //li taglia. // altrimenti aggiorna il contatore else countfield.value = maxlimit - field.value.length; } Codice:
onKeyDown="textCounter(this.form.descrizione, this.form.remLen, 1000);" onKeyUp="textCounter(this.form.descrizione, this.form.remLen, 1000);" Codice:
<input readonly type=text name=remLen size=3 maxlength=4 value="1000"> |
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 |
comparsa cartella con nome avenger...e file di testo..tutto in C:/ | cippico | Sicurezza&Privacy | 2 | 21-06-2009 15.41.27 |
immagine pdf su testo non è stampato da XP | sttrrt | Office suite | 2 | 16-05-2008 13.56.19 |
Limitare la navigazione solo a certi siti: soluzione pratica | gutguy | Sicurezza&Privacy | 1 | 08-02-2007 18.08.50 |
[XP] - Apertura file di testo da file batch | borgata | Programmazione | 2 | 11-04-2006 00.11.07 |
Word2000: selezionare un'immgine che si trova dietro al testo | damiano | Office suite | 7 | 12-07-2005 18.01.15 |