Get the first 4 characters

Is it possible to get the 5.38 in my textbox?
image

Hi @Roie ,

this piece of JS could help you:

fd.spRendered(() => {
  fd.field("NumberField").$on("change", (val) => {
    console.log(val);
    let numberString = val.toString();
    let numberOfCharacters = 4; // Change this value as needed
    let extractedCharacters = numberString.substring(0, numberOfCharacters);
    console.log(extractedCharacters); // Output: "5.3"
  });
});

Try this.

Stepan

1 Like

Hi @StepanS , I tried but it doesn't work.

I know there is slight difference between Plumsail Forms and Plumsail Forms for SharePoint. Is there any erorr in the console log when you hit F12? Find "console" and see the errors/warnings/infos?

The script does return me data.
Stepan

Hey @Roie,

Have you made any adjustments to @StepanS's code?
In its original state the code isn't changing anything on your form, it's just printing the resulting numbers in the console (you can view it by pressing F12).

To put the value in a field on your form you need to replace the line

console.log(extractedCharacters);

with

fd.field('TheNameOfYourTextField').value = extractedCharacters;

Make sure to replace TheNameOfYourTextField with the actual name of your text field.

1 Like

Hi @StepanS and @IliaLazarevskii , thank you!