<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
	

	<script type="text/javascript">
		
		function format(valeur,decimal) {
	separateur=" " ;
// formate un chiffre avec 'decimal' chiffres après la virgule et un separateur
	var deci=Math.round( Math.pow(10,decimal)*(Math.abs(valeur)-Math.floor(Math.abs(valeur)))) ; 
	var val=Math.floor(Math.abs(valeur));
	if ((decimal==0)||(deci==Math.pow(10,decimal))) {val=Math.floor(Math.abs(valeur)); deci=0;}
	var val_format=val+"";
	var nb=val_format.length;
	for (var i=1;i<4;i++) {
		if (val>=Math.pow(10,(3*i))) {
			val_format=val_format.substring(0,nb-(3*i))+separateur+val_format.substring(nb-(3*i));
		}
	}
	if (decimal>0) {
		var decim=""; 
		for (var j=0;j<(decimal-deci.toString().length);j++) {decim+="0";}
		deci=decim+deci.toString();
		val_format=val_format+"."+deci;
	}
	if (parseFloat(valeur)<0) {val_format="-"+val_format;}
	return val_format;
}

function calcTotal()
{
   	var totVal=["Banana", "Orange", "Apple", "Mango"];
	
  	var idx=1;
	var res;
	var totfin ;
	var tva;
	var tvar;
	//	var totBox="qt1"';
	//	var rep='total';

	tva=document.getElementById("tva").value;
	var r = /[-+]?[0-9]*\.?[0-9]+/g
    


	
		totfin=0;
	
	
    for (idx = 1; idx <= 10; idx++) { 
    //alert(totVal[1]);
    totVal[idx] = parseFloat(document.getElementById("qt"+idx).value.replace(',','.'))*parseFloat(document.getElementById("prix"+idx).value.replace(',', '.'));
   	totfin=totfin+totVal[idx];
	totVal[idx]=format((parseFloat(totVal[idx])),2);
    totVal[idx]=totVal[idx].toString();
	totVal[idx]=totVal[idx].replace('.',',');		
	document.getElementById("stot"+idx).value= totVal[idx]+"€";   
	
	
  	// var totVal2 = parseFloat(document.getElementById("qt2").value.replace(',', '.'))+parseFloat(document.getElementById("prix2").value.replace(',', '.'));
   	//totfin=totfin+totVal2;
	//totVal2=totVal2.toString();
	//totVal2=totVal2.replace('.',',');
	//document.getElementById("stot2").value= totVal2;   
	}
	totfin=format((parseFloat([totfin])),2);
	res=totfin.toString();
	res=res.replace('.',',');
	document.getElementById("total").value= res+"€";  
    //catch(e)
    //{}
    document.getElementById("tvar").value= (tva.match(r))[0];  
}
</script>	
<style>
textarea.yel { 
    background: yellow;
	text-align:right;
	padding-right: 10px;
	resize: none;
	
}
	textarea.yel0 { 
    background: yellow;
	text-align:left;
	padding-right: 10px;
	resize: none;
	
}
</style>
	
</head>

<body onload="calcTotal()" >
	

<?php 
$ii=0;
for ($ii=1; $ii<=10; $ii++)
  {
	//print "<form method='post' action='textareatestpost.php'>";
	//print $ii-6;
	//print "<input type='checkbox' value=$ii name='choix[]'>";
	//print "<input type='hidden' value=".$cellb." name='choixtype[]'>";
	print "<textarea class='yel0'  onkeyup='calcTotal()' cols=25 rows=1 id=".chr(34)."des".$ii.chr(34)." name=".chr(34)."qt".$ii.chr(34)." >F&p...</textarea>";
	print "<textarea class='yel' onkeyup='calcTotal()' onclick='this.focus();this.select()' onkeyup='this.select()'cols=4 rows=1 id=".chr(34)."qt".$ii.chr(34)." name=".chr(34)."prix".$ii.chr(34)." >2</textarea>";
	print "<textarea class='yel'  onkeyup='calcTotal()' onclick='this.focus();this.select()'cols=6 rows=1 id=".chr(34)."prix".$ii.chr(34)." name=".chr(34)."qt".$ii.chr(34)." >1,25</textarea>";
	print "<textarea class='yel' onkeyup='calcTotal()' onclick='this.focus();this.select()' cols=4 rows=1 id=".chr(34)."um".$ii.chr(34)." name=".chr(34)."prix".$ii.chr(34)." >M2</textarea>";
	print "<textarea class='yel'  onkeyup='calcTotal()' cols=8 rows=1  id=".chr(34)."stot".$ii.chr(34)." name=".chr(34)."stot".$ii.chr(34)." >0</textarea>";
	print "<br>";
	
} // end for	
	print "<textarea class='yel' cols=9 rows=1 name='total' id='total'>0</textarea>";
	
//<input type="text" id="total" value="0"  />
	?>

<textarea class='yel0'  onkeyup='calcTotal()' cols=25 rows=1 id="tva" name="tva" >tva 6%</textarea>
<textarea class='yel0'  onkeyup='calcTotal()' cols=25 rows=1 id="tvar" name="tvar" >tva 6%</textarea>
	
	
</body>
</html>
