Javascript issue

Moderator: crythias

Post Reply
sansflance
OTRS newbie
Posts: 14
Joined: 18 Dec 2018, 16:38
OTRS Version?: OTRS6.0
Real Name: Sam

Javascript issue

Post by sansflance » 30 Nov 2019, 04:56

Hi, Can someone please advise me where am i going wrong in below.

DynamicField_PrQuantity1-10 are input type text.
DynamicField_PrPrice1-10 are select dropdown
DynamicField_PrQuotationAmount is a text field.
For any change in Quantity field, i have to multiply it with price for all 10 fields and keep the total in PrQuotationAmount value.


var Quantities = ['DynamicField_PrQuantity','DynamicField_PrQuantity2','DynamicField_PrQuantity3','DynamicField_PrQuantity4','DynamicField_PrQuantity5','DynamicField_PrQuantity6','DynamicField_PrQuantity7','DynamicField_PrQuantity8','DynamicField_PrQuantity9','DynamicField_PrQuantity10'],
Prices = ['DynamicField_PrPrice','DynamicField_PrPrice2','DynamicField_PrPrice3','DynamicField_PrPrice4','DynamicField_PrPrice5','DynamicField_PrPrice6','DynamicField_PrPrice7','DynamicField_PrPrice8','DynamicField_PrPrice9','DynamicField_PrPrice10'];

$.each(Quantities).on('blur', function () {
var QuotationAmount=0;
for ( i=0; i<10; i++){
var Price=$("#" + Prices).val();
var Quantity = $("#" + Quantities).val();
if ( Quantity != '' ){
var RawPrice = Price.substring(Price.indexOf("_")+1) || 0;
QuotationAmount=QuotationAmount + (RawPrice * Quantity );
}
}
$('#DynamicField_PrQuotationAmount').innerHTML = QuotationAmount;
});
};

zzz
OTRS superhero
Posts: 305
Joined: 15 Dec 2016, 15:13
OTRS Version?: 3.x - 6.0.x
Real Name: Emin Yazi
Company: Efflux GmbH
Contact:

Re: Javascript issue

Post by zzz » 30 Nov 2019, 18:06

Hi,

Well, for multiple reasons on the JS code.
Are you trying to go for PrQuotationAmount = (PrQuantity1 * PrPrice1) + (PrQuantity2 * PrPrice2) etc.?

Best regards
Emin
Professional OTRS services for development, consulting, hosting and support:
efflux.de – German | efflux.de/en/ – English

Free and premium OTRS add-ons (TextModule, AdBlocker, ModernSkin ... growing): portal.efflux.de

Post Reply