1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
   |  
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
  <head>
    <title>Titre</title>
		<meta http-equiv="Content-type" content="text/html; charset=ISO-8859-1" />
		<script type="text/javascript">
			var tax_rates = new Array();
			tax_rates["1"] = 7.6;
 
			function doRound(x, places) 
			{
				return Math.round(x * Math.pow(10, places)) / Math.pow(10, places);
			}				 
 
			//-------------------------------------------------------------------------
			//-- les paramètres passés à la fonction :
			//-- formulaire : pointeur sur le formulaire,
			//-- valeur : valeur du champ saisi,
			//-- typeTaxe : nom du champ select,
			//-- champAMettreAJour : nom du champ à mettre à jour,
			//-- typeCalcul : signe arithmétique du calcul => * ou /.
			//-------------------------------------------------------------------------
			function calcul(formulaire, valeur, typeTaxe, champAMettreAJour, typeCalcul)
			{
				//-- si la valeur saisie n'est pas numérique, on dégage --------------
				if (isNaN(valeur)) return;
 
				with (formulaire)
				{
					//-- si la valeur du select = 0, on dégage -------------------------
					var indiceTaxe = elements[typeTaxe].options[elements[typeTaxe].selectedIndex].value;
					if (indiceTaxe == 0) return;
 
					var coef = (tax_rates[indiceTaxe] /100) + 1;
					elements[champAMettreAJour].value = doRound(eval(valeur  + typeCalcul + coef), 4);
				}
			}
		</script>
  </head>
	<body>
		<form name="new_product">
			<input size="6" type="text" name="att_price[0]" value="" onchange="calcul(this.form, this.value, 'products_tax_class_id[0]', 'att_price_gross[0]', '*')" /> 
			<select name="products_tax_class_id[0]" onchange="calcul(this.form, this.value, 'type_taxe[0]', 'prix_ttc[0]', '*')">
				<option value="0">-- aucun --</option>
				<option value="1" selected="selected">TVA</option>
			</select>
			<input type="text" name="att_price_gross[0]" onkeyup="calcul(this.form, this.value, 'products_tax_class_id[0]', 'att_price[0]', '/')" /> 
    </form>
  </body>
</html> | 
Partager