1

I am attempting to use autonumeric.js multiple to populate the value of the non-DisplayOnly field with the numeric value of the DisplayOnly field. I am using the class "autonumeric-currency" to identify the DisplayOnly field. I have much more html, using the same naming convention (with DisplayOnly suffix = DisplayOnly field, without is the field that needs the numeric value).

I have a working example, just wanted to check if I am using the appropriate technique.

HTML

    <div class="form-group">
        <label asp-for="LoanEstimate.AnnualTaxes" class="control-label"></label>
        <input asp-for="LoanEstimate.AnnualTaxesDisplayOnly" class="form-control autonumeric-currency" />
        <input asp-for="LoanEstimate.AnnualTaxes" class="form-control" type="hidden"/>
        <span asp-validation-for="LoanEstimate.AnnualTaxes" class="text-danger"></span>
    </div>

javascript

$(document).ready(function ($) 

        const anElement = AutoNumeric.multiple('.autonumeric-currency', {
            currencySymbol: "$"
        }); 

        $(".autonumeric-currency").on('keyup', function () {
            //I want to set the value of the id that matches this.id minus the DisplayOnly Suffix using getNumericString()
            var str = this.id
            var getThis = str.substring(0, str.indexOf("DisplayOnly"))
            $("#" + getThis).val(AutoNumeric.getNumericString("#" + this.id));
        });


});
MaxPowers
  • 474
  • 1
  • 4
  • 18

0 Answers0