ncaffrey
ncaffrey

Reputation: 23

Adobe JavaScript - Summing two values with a comma

This is my code so far:

this.getField("price_config").setAction("onBlur", "calcSumElementprice()");
this.getField("amount").setAction("Keystroke", "calcSumElementprice()");

function calcSumElementprice(){

var priceConfig = this.getField("price_config").value;
app.alert("type priceConfig "  + typeof priceConfig + " Number " + priceConfig);

var amount = this.getField("amount").value;
app.alert("type amount "  + typeof amount + " Number " + amount);

var totalElementPrice = priceConfig * amount;    
var totalElementPriceValue = totalElementPrice ? parseFloat(totalElementPrice) : 0;
var totalPrice = totalElementPriceValue;

this.getField("Elementprice").value = totalPrice.toFixed(2).replace(".", ",");

Either I select amount or enter something in price_config, then the calcSumElementprice function is called.

For example, if I enter 200 for price_config, the calculation works perfectly. price_config and amount are then of type number. It also works with numbers that contain a point, e.g. 200.99 .

But if I enter 200.99, then priceConfig becomes a string. And the whole calculation no longer works, of course.

hat do I have to change so that both number variants (200 = whole numbers; 200,99 = numbers with commata) work?

Upvotes: 0

Views: 38

Answers (0)

Related Questions