Forse cosi (ma da migliorare)
codice:
<html>
<head>
<title>Untitled</title>
<style type="text/css">
<!--
.readonly {background-color:yellow}
-->
</style>
<script language="JavaScript" type="text/javascript">
<!--
var cpVal = 0;
var prevCp = '';
var cpAmm = 0;
function cambiaValore(anId,unValore) {
if (prevCp != '') {
document.getElementById(prevCp).value='--';
} // if (prevCp != '')
prevCp = anId;
document.getElementById(prevCp).value=unValore;
cpAmm = unValore;
calcolaTotale();
} // function cambiaValore(anId,unValore)
function servizio(aCB,unServizio,unValore) {
statoCB = aCB.checked;
serv = 'servizio'+unServizio;
qta = 'quanti'+unServizio;
errore = false;
if (isNaN(document.getElementById(qta).value)) {
alert('Quantita del servizio '+unServizio+' non numercia');
errore = true;
} else {
if (document.getElementById(qta).value <= 0) {
alert('Quantita del servizio '+unServizio+' uguale a 0 o minore di 0');
errore = true;
} // if (document.getElementById(qta).value <= 0)
} // if (isNaN(document.getElementById(qta).value))
if (errore) {
aCB.checked = false;
document.getElementById(serv).value='--';
document.getElementById(qta).value=1;
return;
} // if (errore)
if (statoCB) {
document.getElementById(serv).value=unValore;
} else {
document.getElementById(serv).value='--';
document.getElementById(qta).value=1;
} // if (statoCB)
calcolaTotale();
} // function servizio(statoCB,unServizio,unValore)
function calcolaTotale() {
oColl = document.getElementsByTagName('INPUT');
tot = 0;
for (i=0;i<oColl.length;i++) {
curInput = oColl.item(i);
if (curInput.type == 'checkbox' && curInput.name.substr(0,2) == 'SA') {
serv = 'servizio' + curInput.value;
qta = 'quanti' + curInput.value;
if (curInput.checked && document.getElementById(serv).value != '--') {
tot += parseFloat(document.getElementById(serv).value) * parseFloat(document.getElementById(qta).value);
} // if (curInput.checked && document.getElementById(serv).value != '--')
} // if (curInput.type == 'checkbox' && curInput.name.substr(0,2) == 'SA')
} // for (i=0;i<oColl.length;i++)
document.getElementById('totale').value = tot + parseFloat(cpAmm);
} // function calcolaTotale()
function controllaQta(unServizio) {
qta = 'quanti'+unServizio;
errore = false;
if (isNaN(document.getElementById(qta).value)) {
alert('Quantita del servizio '+unServizio+' non numercia');
errore = true;
} else {
if (document.getElementById(qta).value <= 0) {
alert('Quantita del servizio '+unServizio+' uguale a 0 o minore di 0');
errore = true;
} // if (document.getElementById(qta).value <= 0)
} // if (isNaN(document.getElementById(qta).value))
if (errore) {
document.getElementById(qta).value=1;
} // if (errore)
calcolaTotale();
}
//-->
</script>
</head>
<body>
<input type="radio" value="1" name="PH" onFocus="cambiaValore('cp1','18.00');"><input class="readonly" type="text" size="6" id="cp1" name="cp1" value="--" readonly>
<input type="radio" value="2" name="PH" onFocus="cambiaValore('cp2','36.00');"><input class="readonly" type="text" size="6" id="cp2" name="cp2" value="--" readonly>
<input type="radio" value="3" name="PH" onFocus="cambiaValore('cp3','48.00');"><input class="readonly" type="text" size="6" id="cp3" name="cp3" value="--" readonly>
<input type="radio" value="4" name="PH" onFocus="cambiaValore('cp4','72.00');"><input class="readonly" type="text" size="6" id="cp4" name="cp4" value="--" readonly>
<input type="radio" value="5" name="PH" onFocus="cambiaValore('cp5','45.60');"><input class="readonly" type="text" size="6" id="cp5" name="cp5" value="--" readonly>
<hr />
<input type="checkbox" value="1" name="SA" onClick="servizio(this,'1','1800');"> servizio 1 <input class="readonly" type="text" size="6" id="servizio1" name="servizio1" value="--" readonly>
<input type="hidden" size="6" id="quanti1" name="quanti1" value="1">
<input type="checkbox" value="2" name="SA" onClick="servizio(this,'2','3360');"> servizio 2 <input class="readonly" type="text" size="6" id="servizio2" name="servizio2" value="--" readonly>
<input type="hidden" size="6" id="quanti2" name="quanti2" value="1">
<input type="checkbox" value="3" name="SA" onClick="servizio(this,'3','6000');"> servizio 3 <input class="readonly" type="text" size="6" id="servizio3" name="servizio3" value="--" readonly>
<input type="hidden" size="6" id="quanti3" name="quanti3" value="1">
<input type="checkbox" value="4" name="SA" onClick="servizio(this,'4','7200');"> servizio 4 <input class="readonly" type="text" size="6" id="servizio4" name="servizio4" value="--" readonly>
Quantità : <input type="text" size="6" onblur="controllaQta('4');" id="quanti4" name="quanti4" value="1">
<hr />
Totale : <input class="readonly" type="text" size="6" name="totale" id="totale" readonly value="0">
</body>
</html>