Prova a modificare un po questo script:
codice:
<html>
<head>
<title>Untitled</title>
<script>
max=3
var price=new Array(max);
var descr=new Array(max);
var totale=0;
var vai=true;
function prezzo(nome,n){
price[n]=document.comp.elements[nome][document.comp.elements[nome].selectedIndex].value;
descr[n]=document.comp.elements[nome][document.comp.elements[nome].selectedIndex].text;
document.getElementById(nome+'V').innerHTML=price[n]==0?"":price[n];
calcola();
}
function calcola() {
totale=0;
for(i=0;i<max;i++){
if(isNaN(parseInt(price[i])))x=0
else x=parseInt(price[i]);
totale=totale+x;
};
document.getElementById('totale').innerHTML=totale;
}
function avanti() {
document.write('<h1>Preventivo</h1><table border=0 cellpadding="4">');
for(i=0;i<price.length;i++)document.write('<tr><td>'+descr[i]+'</td><td>'+price[i]+'</td></tr>');
document.write('</table>');
document.write('<hr width="30%" align="left"><h3>Totale= '+totale+'</h3>');
}
function controlla() {
for(i=0;i<max;i++){
if((price[i]==0)||(isNaN(price[i])))vai=false
};
if(vai)avanti()
else alert("Compilare tutti i campi");
vai=true;
}
</script>
</head>
<body>
<form name="comp">
<fieldset><legend>Computer</legend>
<label>Processore:
<select name="processore" onchange="prezzo(this.name,0)">
<option value="0"></option>
<option value="100">xxx</option>
<option value="200">yyy</option>
<option value="300">zzz</option>
</select><span id="processoreV"></span></label>
<label>Ram:
<select name="ram" onchange="prezzo(this.name,1)">
<option value="0"></option>
<option value="100">xxx</option>
<option value="200">yyy</option>
<option value="300">zzz</option>
</select><span id="ramV"></span></label>
<label>MB:
<select name="MB" onchange="prezzo(this.name,2)">
<option value="0"></option>
<option value="100">xxx</option>
<option value="200">yyy</option>
<option value="300">zzz</option>
</select><span id="MBV"></span></label>
</fieldset>
</form>
Totale:<span id="totale">0</span>
<button onclick="controlla()">Avanti >></button>
</body>
</html>