Ciao ragazzi ho questo form che mi sta facendo mandare ai pazzi, devo far si che il totale venga calcolato il base all'oggetto spuntato per il valore inserito nel campo grammi, il problema è che gli input da spuntare hanno un valore dinamico che viene aggiornato via csv e dopo deve subire un ulteriore moltiplicazione, credo di aver fatto tutti i passaggi possibili non capisco ma il form non esegue il calcolo... non riesco a capire dove è l'errore aiutatemi voi :crying:
Codice:
<html>
<head>
<script type="text/javascript">
function processForm() {
//get form variables
var theItems = document.getElementsByName( "item" );
var theQty = Number( document.getElementById( "qty" ).value );
var thePrice = Number( document.getElementById( "price" ).value);
//variable for selected item
var selectedItem;
//variable for order total
var orderTotal = 0.00;
//the display box
var outBox = document.getElementById( "total" );
//set selectedItem = checked item
for(var i = 0; i < theItems.length; i++) {
if( theItems[i].checked) {
selectedItem = theItems[i].value;
break;
}
}
//get price for selected item
switch(selectedItem) {
case "A":
total = thePrice * 0.916;
break;
case "B":
total = thePrice * 0.999;
break;
default:
total = 0.00;
}
//figure final total
total = (selectedItem * theQty);
//output to text box
outBox.value = "€ " + total.toString();
}
</script>
</head>
<body>
<?php
$remoteFileAddr = "http://dodygold1.altervista.org/csv/oro.csv";
// apri il file in lettura
$fr = fopen($remoteFileAddr, 'r');
// crei un arrary che conterra le righe
$righe = array();
// cicli il file
while (!feof($fr)) {
// riempi l'array
$righe[] = fgets($fr);
}
// a te interessa il secondo elemento che contiene il numero quindi $righe[1]
echo <<< FORM
<form id="form1" action="" method="get">
22KT <input type="radio" name="item" value="A" /> 24KT <input type="radio" name="item" value="B" /><br>
Valore del Fixing di Londra -0.40cent<br>
<input type="text" id="price" size="20" maxlength="20" readonly="readonly" value="{$righe[1]}" /><br>
Peso in Grammi: <input type="text" id="qty" size="10" maxlength="10" value="1" /><br>
Totale: <input type="text" id="total" size="20" maxlength="20" readonly="readonly" value="0.00" /><br>
<input type="button" id="submit" value="Calcola il Totale" onclick="processForm()" />
</form>
FORM;
?>
</body>
</html>