Expand my Community achievements bar.

SOLVED

Capturing First word from a textbox

Avatar

Level 1

Okay, small issue, I can't figure out how to grab the first word from several in a text box. Here is the code that captures the full line:

var LSTN = "LSTN"+xfa.form.OUTSTCHK12.FormPage1.Subform1.PayeeLastName.rawValue;

If someone could please help I would be very greatful.

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Well now that you know ho to get the word it is simply a case of assigning it to another field. Assuming the other field is called OtherField you would use a command like this:

OtherField.rawValue = words[0]

Paul

View solution in original post

4 Replies

Avatar

Former Community Member

You can use javascript functions for that. Assuming your field that holds the sentence is PayeeLastName then you can do something like this:

     // Get value into a string

     var message = PayeeLastName.rawValue;

     //Use the split command to break up the string on the space char and place into an array called words

     var words = message.split(" ");

     //now the words array holds all of the words in the string. It is a zero base array so to get the 1st word

     app.alert("The first word is: " + words[0]);

Hope that helps

Paul

Avatar

Level 1

Your answer was helpful but I believe I phrased my question wrong, is there a way to grab just the first word and have it fill a different box instead of having the app.alert for the word.

Thanks

PS: Would it be possible to only change part of the code that I pasted to grab the first word and continue to place it where it's set to do so?

Avatar

Correct answer by
Former Community Member

Well now that you know ho to get the word it is simply a case of assigning it to another field. Assuming the other field is called OtherField you would use a command like this:

OtherField.rawValue = words[0]

Paul

Avatar

Level 1

Thank you for helping me out, it is greatly appreciated.

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----