Ciao ragazzi sto sviluppando un form che dovrebbe in teoria moltiplicare un campo A per campo B
non sembra difficile, ma il campo A è una cifra che viene aggiornata via CSV, quindi devo eseguire un parser.
Con queste cose sono agli inizi ma vi posto quello che sono riuscito a buttar giu... praticamente un minestrone.
Diciamo che quando vado a provarlo mi triplica il form e non capisco il perchè e non è l'unico errore, perfavore aiutatemi voi :crying:
non sembra difficile, ma il campo A è una cifra che viene aggiornata via CSV, quindi devo eseguire un parser.
Con queste cose sono agli inizi ma vi posto quello che sono riuscito a buttar giu... praticamente un minestrone.
Diciamo che quando vado a provarlo mi triplica il form e non capisco il perchè e non è l'unico errore, perfavore aiutatemi voi :crying:
PHP:
<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;
case "C":
total = 0.00;
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";
$content = file_get_contents($remoteFileAddr) or die ("error");
$seperator = ";";
$nPos = strpos($content,"\n");
$firstLine = substr($content, 0, $nPos);
// subtracting first line(column titles) from main content
$content = substr($content, $nPos, strlen($content));
$colNum = substr_count($firstLine, $seperator);
// Exploding First Line for Column titles
$tree = explode($seperator, $firstLine);
// Parsing Data
// Exploding content line by line
$lbl = explode("\n", $content);
$conCount = count($lbl);
echo "\n";
foreach ($lbl as $line) {
$i = 0;
// Exploding content with seperator
$cols = explode($seperator, $line);
foreach ($cols as $col) {
echo <<< FORM
<form id="form1" action="" method="get">
22KT <input type="radio" name="item" value="A" /> 24KT <input type="radio" name="item" value="B" />
<input type="text" id="price" size="20" maxlength="20" readonly="readonly" value="{$col}" />
Peso in Grammi: <input type="text" id="qty" size="10" maxlength="10" value="0" />
Totale: <input type="text" id="total" size="20" maxlength="20" readonly="readonly" value="0.00" />
<input type="button" id="submit" value="Calcola il Totale" onclick="processForm()" />
</form>
FORM;
}
}
?>
</body>
</html>