Zu 1.
Orginal:
function CalculateAndUpdate(){
var price_field = document.getElementById("test_product_price");
var m = prices.length;
var cur_price=0;
for (i=0;i <= m;i++){
if (prices[i]){
cur_price += prices[i];
}
}
price_field.innerHTML=formatCurrency(cur_price);
}
wird in etwa:
function CalculateAndUpdate(){
var price_field = document.getElementById("test_product_price");
var amount_field = document.getElementById("test_product_amount");
var m = prices.length;
var cur_price=0;
for (i=0;i <= m;i++){
if (prices[i]){
cur_price += prices[i];
}
}
var myamount = amount_field.value;
myamount += 1;
amount_field.value = myamount;
price_field.innerHTML=formatCurrency(cur_price);
}
Zu 2:
Im Template, such dir die stelle, an der die Listen eingebaut werden und statt
<select id="test_select_[{$product->oxarticles__oxid->value}]_[{$iSel}]"
name="sel[[{$iSel}]]" onchange="change_price(this);">
machst du
<select id="test_select_[{$product->oxarticles__oxid->value}]_[{$iSel}]"
name="sel[[{$iSel}]]" onchange="change_price(this,'ID_PREIS_FELD');">
Damit übergibst du die ID des Preisfeldes an die funktion change_price. Die sollte so ungefähr aussehen:
function change_price(selectobj,priceid){
var opti_field=selectobj.selectedIndex;
var idx=selectobj.options[opti_field].getAttribute("rev");
var opti=selectobj.options[opti_field].getAttribute("rel");
if (idx >=0){
idx++;
if (opti){
prices[idx] = parseFloat(opti.replace(/,/g,"."));
}else{
prices[idx] = 0.0;
}
}
CalculateAndUpdate(priceid);
}
Sie reicht also einfach die ID weiter an CalculateAndUpdate weiter. Die sollte ungefähr so aussehen:
function CalculateAndUpdate(priceid){
var price_field = document.getElementById(priceid);
var m = prices.length;
var cur_price=0;
for (i=0;i <= m;i++){
if (prices[i]){
cur_price += prices[i];
}
}
price_field.innerHTML=formatCurrency(cur_price);
}
Das ganze ist aus der hohlen Hand und nicht getestet, sollte dir aber den grundsätzlichen Weg zeigen