Extract numbers from a string?

Aeden Frost
Tera Contributor

Hi everyone, hope you're having a nice day.

 

I have a field for a string with a number (Eg. Box of 100)

I want to be able to extract the number from the string (100) and move that field to another field to be used in another string field.

 

I've made a client script like this but it does not seem to be working in the way that is intended, any help would be much appreciated 🙂

function onSubmit() {
	
var txt = ('u_internal_unit');
var numb = txt.match(/\d/g);
numb = numb.join("");
var ans = ('iui_amount');	
ans = (numb); 
	
}
1 ACCEPTED SOLUTION

g_form.getValue('<field name>') will get the value of the field.

g_form.setValue('<field name>', <value>) will set the value to the field.

View solution in original post

7 REPLIES 7

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Aeden,

Try below. To get the value of a field, use g_form.getValue(),

function onSubmit() {
	
var txt = g_form.getValue('u_internal_unit');
var numb = txt.match(/\d/g);
numb = numb.join("");

ans = g_form.setValue('iui_amount', numb); 
	
}

g_form.getValue('<field name>') will get the value of the field.

g_form.setValue('<field name>', <value>) will set the value to the field.

Working perfectly! Finished code is as follows

function onSubmit() {
	
var txt = g_form.getValue('u_internal_unit');
var numb = txt.match(/\d/g);
numb = numb.join("");
var ans = ('u_iui_amount');	
ans = (numb); 
g_form.setValue('u_iui_amount', ans)	
}