0

I have a form with multiple SharePoint fields set as "currency". How do I put a currency field value into a variable? I've tried several version, such as:

var txt01TotCash = $("input[id='Total_x0020_Cash__2abd298c-4fee-401a-b51a-d48afd27a395_$CurrencyField']").text();

and

var txt01TotCash = $("input[id='Total_x0020_Cash__2abd298c-4fee-401a-b51a-d48afd27a395_$CurrencyField']").val();

and

var txt01TotCash = $("input[title='Total Cash']").val();

The error I get is val is not a function or text is not a function.

Any ideas?

Thanks!

1 Answer 1

1

By Looking at your code, Either jQuery is not loaded properly or your selector for currency is wrong:

Try below code:

  1. Using Plain JavaScript:
    var currencyField = document.querySelector("input[title^='Currency']"); //Here "Currency" is display name of field.
    var currencyValue = currencyField.value;
    currencyField.addEventListener('change', function() {
        var currencyValue = currencyField.value;
    });
    console.log(currencyValue);
  1. Using jQuery:
    $(document).ready(function() {
        var currencyValue = $("input[title^='Currency']").val(); //Here "Currency" is display name of field.

        $("input[title^='Currency']").change(function() {
            currencyValue = $("input[title^='Currency']").val();
            console.log(currencyValue);
        });
    });

Make sure jQuery file is loaded properly.

1
  • Hi, does this answers your question? If yes, please accept it as an answer. Commented Aug 23, 2019 at 6:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.