
Originariamente inviata da
m4rko80
Mancava una graffa al codice(funziona calcola)
codice:
<html>
<head>
<script>
var unit = 5;
var min = 0;
var currentValue;
var currentText;
window.onLoad = function(){
currentValue = document.getElementById('valore').value || 0;
currentText = document.getElementById('testo').value;
}
function calcola(event){
var key = event.which || event.keyCode;
var inp = String.fromCharCode(key);
if (/[a-zA-Z0-9]/.test(inp) || (key==8)){ //Tasti accettati : lettere e numeri
currentText = document.getElementById('testo').value;
console.log(key, document.getElementById('testo').value.length)
var newValue = document.getElementById('testo').value.length * 5;
document.getElementById('valore').value = newValue;
}else{
//caratteri non consentiti = reset testo
document.getElementById('testo').value = currentText;
}
}
</script>
</head>
<body>
Testo <input type="text" id="testo" value="" onKeyup="javascript:calcola(event);"/>
Valore <input type="text" id="valore" value="0">
</body>
</html>
Il codice a se stante funziona, manca la gestione per il testo, il quale comprende il caratter euro o meno.
Il fatto che stia in un plugin è già più complesso, se devi modificare un plugin potrebbe essere legato ad altro ma non posso vedere e avere idea di cosa ci sia dietro.
Da questo esempio bene o male puoi farti un'idea di come continuare.