function calcolacosto(val){ val=parseInt(val); var costoscheda=2.5; if (val>=1000) { costoscheda=1.49; } else { if (val>=500) { costoscheda=1.79; } else { if (val>=100) { costoscheda=1.99; } else { if (val>=50) { costoscheda=2.19; } else { if (val>=10) { costoscheda=2.39; } else { costoscheda=2.49; } } } } } var costofinale=val*costoscheda*100; costofinale=parseInt(costofinale); if (isNaN(costofinale)) { alert ('Inserire una cifra nella casella'); document.getElementById('costoschede').innerHTML="--"; } else { if (costofinale>3000*costoscheda*100) { alert ('Il numero massimo di pacchetti di schede acquistabili e\' di 3000'); document.getElementById('n_schede').value=3000; document.getElementById('costoschede').innerHTML=(3000*costoscheda*100)/100; } else { if (costofinale<0) { alert ('Inserire un numero positivo di pacchetti di schede'); document.getElementById('costoschede').innerHTML="--"; } else { costofinale=costofinale/100; document.getElementById('costoschede').innerHTML=costofinale; } } } }