var request = null; var netto_sum = 0; function calculatePrices() { netto_sum = 0; var price = 0; var quantity = 0; var position = 0; var ajax_url = "calculatePaketpreis.php?id_land=" + document.getElementById('id_land').value; price = document.getElementById("order_price_45").value; quantity = document.getElementById("order_quantity_45").value; position = price*quantity; ajax_url = ajax_url + "&_product45=" + quantity; netto_sum = netto_sum + position; document.getElementById("order_position_45").value = kaufm(position); price = document.getElementById("order_price_44").value; quantity = document.getElementById("order_quantity_44").value; position = price*quantity; ajax_url = ajax_url + "&_product44=" + quantity; netto_sum = netto_sum + position; document.getElementById("order_position_44").value = kaufm(position); price = document.getElementById("order_price_43").value; quantity = document.getElementById("order_quantity_43").value; position = price*quantity; ajax_url = ajax_url + "&_product43=" + quantity; netto_sum = netto_sum + position; document.getElementById("order_position_43").value = kaufm(position); price = document.getElementById("order_price_40").value; quantity = document.getElementById("order_quantity_40").value; position = price*quantity; ajax_url = ajax_url + "&_product40=" + quantity; netto_sum = netto_sum + position; document.getElementById("order_position_40").value = kaufm(position); price = document.getElementById("order_price_39").value; quantity = document.getElementById("order_quantity_39").value; position = price*quantity; ajax_url = ajax_url + "&_product39=" + quantity; netto_sum = netto_sum + position; document.getElementById("order_position_39").value = kaufm(position); price = document.getElementById("order_price_42").value; quantity = document.getElementById("order_quantity_42").value; position = price*quantity; ajax_url = ajax_url + "&_product42=" + quantity; netto_sum = netto_sum + position; document.getElementById("order_position_42").value = kaufm(position); price = document.getElementById("order_price_49").value; quantity = document.getElementById("order_quantity_49").value; position = price*quantity; ajax_url = ajax_url + "&_product49=" + quantity; netto_sum = netto_sum + position; document.getElementById("order_position_49").value = kaufm(position); price = document.getElementById("order_price_41").value; quantity = document.getElementById("order_quantity_41").value; position = price*quantity; ajax_url = ajax_url + "&_product41=" + quantity; netto_sum = netto_sum + position; document.getElementById("order_position_41").value = kaufm(position); price = document.getElementById("order_price_48").value; quantity = document.getElementById("order_quantity_48").value; position = price*quantity; ajax_url = ajax_url + "&_product48=" + quantity; netto_sum = netto_sum + position; document.getElementById("order_position_48").value = kaufm(position); price = document.getElementById("order_price_47").value; quantity = document.getElementById("order_quantity_47").value; position = price*quantity; ajax_url = ajax_url + "&_product47=" + quantity; netto_sum = netto_sum + position; document.getElementById("order_position_47").value = kaufm(position); price = document.getElementById("order_price_46").value; quantity = document.getElementById("order_quantity_46").value; position = price*quantity; ajax_url = ajax_url + "&_product46=" + quantity; netto_sum = netto_sum + position; document.getElementById("order_position_46").value = kaufm(position); ajax(ajax_url); } function calculatePricesAjaxHandler() { switch(request.readyState) { case 0: case 1: case 2: case 3: return; case 4: var versand_gebuehr = request.responseText; break; } versand_gebuehr = parseFloat(versand_gebuehr); document.getElementById("order_sum_netto").value = kaufm(netto_sum); var ust = netto_sum*0.2; document.getElementById("order_sum_ust").value = kaufm(ust); document.getElementById("order_sum_brutto").value = kaufm(netto_sum + ust); document.getElementById('order_versand_gebuehr').value = kaufm(versand_gebuehr); if((netto_sum + ust) < 40 && netto_sum > 0) { document.getElementById("order_sum_gebuehr").value = kaufm(5); document.getElementById("order_sum_all").value = kaufm(netto_sum + ust + 5 + versand_gebuehr); } else { document.getElementById("order_sum_gebuehr").value = kaufm(0); document.getElementById("order_sum_all").value = kaufm(netto_sum + ust + versand_gebuehr); } } function kaufm(x) { var k = (Math.round(x * 100) / 100).toString(); k += (k.indexOf('.') == -1)? '.00' : '00'; return k.substring(0, k.indexOf('.') + 3); } function ajax(url) //der onclick Event wird nach dem Laden des Dokuments an den Tag "button angehängt { request = createRequest(); //funktion zum erstellen des XMLHttpRequest Objekts request.onreadystatechange = calculatePricesAjaxHandler; //Keine Klammern() da sonnst die Funktion ausgeführt wird; Sie soll aber nur verknüpft werden request.open("GET", url , true); request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=iso-8859-1'); //request.setMimeType('Content-Type','text/html; charset=ISO-8859-1'); request.send(null); // die übergabe eines Wertes ist in diesem Fall sehr wichtig, da sonnst inkompatibilitäten auftreten könnten } function createRequest() { try { var request = new XMLHttpRequest(); } catch(ex) { try { var request = new ActiveXObject("MSXML2.XMLHTTP"); } catch(ex) { var request = new ActiveXObject("Microsoft.XMLHTTP"); } } return request; }