You are viewing limited content. For full access, please sign in.

Question

Question

Reformatting value retrieved from look up

asked on January 25, 2016 Show version history

We are populating a form value form a look up.  The field is populated from a num_val.  How can I remove the decimal and trailing zeros from the form field.  For example, it will place "123456.00000" in the field after doing the lookup and I only want 123456 in the field.

Thanks,

0 0

Replies

replied on January 25, 2016

Attach an onchange event handler to the field that's the target of the lookup, and process its value inside the anonymous function callback. Example:

$("#Field5").on("change", function() {
    var newVal = parseInt($(this).val());
    newVal.toString();
    $(this).val(newVal);
});

(In this case, a quick way to strip trailing zeroes is to convert the value of the field to a number first, and then to convert it back to a string.)

0 0
replied on January 26, 2016

Thanks for your reply, Ege.  This isn't working for me just yet but I'll keep playing with it.

0 0
replied on January 26, 2016

Make sure to include the above code snippet inside a document.ready block (and of course update your Field ID). Example:

$(document).ready(function() {
    $("#Field5").on("change", function() {
        var newVal = parseInt($(this).val());
        newVal.toString();
        $(this).val(newVal);
    });
});

This works for me when I test it using a simple lookup.

0 0
replied on January 26, 2016

Are use using Forms with number of decimal places configured? If so , will change number of decimal places to 0 works for you?

0 0
replied on January 26, 2016

No, it is not configured with a number of decimal places.  I wish it were that simple.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.