Telefonino.net network
 
| 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 » |

Torna indietro   WinTricks Forum > Software > Programmazione

Notices

Rispondi
 
Strumenti discussione
Vecchio 21-07-2008, 21.08.26   #1
Alhazred
Made in Japan
Top Poster
 
L'avatar di Alhazred
 
Registrato: 04-07-2001
Messaggi: 4.461
Alhazred promette bene
[JSP] Limitare testo in una textarea

Ho una JSP il cui codice è questo:
[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>&nbsp;</td><td>&nbsp;</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?
Alhazred non è collegato   Rispondi citando
Vecchio 22-07-2008, 10.14.10   #2
miciomao
Hero Member
 
L'avatar di miciomao
 
Registrato: 14-01-2005
Loc.: Rome, Italy
Messaggi: 1.132
miciomao promette bene
é 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é!
miciomao non è collegato   Rispondi citando
Vecchio 22-07-2008, 10.36.11   #3
Alhazred
Made in Japan
Top Poster
 
L'avatar di Alhazred
 
Registrato: 04-07-2001
Messaggi: 4.461
Alhazred promette bene
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;
}
Chiamandola così
Codice:
onKeyDown="textCounter(this.form.descrizione, this.form.remLen, 1000);" onKeyUp="textCounter(this.form.descrizione, this.form.remLen, 1000);"
e questo è il contatore
Codice:
<input readonly type=text name=remLen size=3 maxlength=4 value="1000">
Alhazred non è collegato   Rispondi citando
Rispondi


Utenti attualmente attivi che stanno leggendo questa discussione: 1 (0 utenti e 1 ospiti)
 
Strumenti discussione

Regole di scrittura
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is ON
Gli smilies sono ON
[IMG] è ON
Il codice HTML è OFF

Vai al forum

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 16.41.27
immagine pdf su testo non è stampato da XP sttrrt Office suite 2 16-05-2008 14.56.19
Limitare la navigazione solo a certi siti: soluzione pratica gutguy Sicurezza&Privacy 1 08-02-2007 19.08.50
[XP] - Apertura file di testo da file batch borgata Programmazione 2 11-04-2006 01.11.07
Word2000: selezionare un'immgine che si trova dietro al testo damiano Office suite 7 12-07-2005 19.01.15

Orario GMT +2. Ora sono le: 10.18.41.


E' vietata la riproduzione, anche solo in parte, di contenuti e grafica.
Copyright © 1999-2017 Edizioni Master S.p.A. p.iva: 02105820787 • Tutti i diritti sono riservati
L'editore NON si assume nessuna responsabilità dei contenuti pubblicati sul forum in quanto redatti direttamente dagli utenti.
Questi ultimi sono responsabili dei contenuti da loro riportati nelle discussioni del forum
Powered by vBulletin - 2010 Copyright © Jelsoft Enterprises Limited.