Expand my Community achievements bar.

SOLVED

Javascript question - take user input and use in other fields with changed case (i.e in one field as uppercase and in anohter as capatilsed each)

Avatar

Level 2

Hi ther,

Ive been away from Livecucle for a while and have lost a handle on the coding.

I'm tyring to get the data from one filed to also be repeated in two other fields with different formatting (uppercase and capatilise each word)

So if user enters "james michael smith" into a filed named - say - fullanme - it would also be reproduced in a file fullnameCaps  - changed to all caps in that feild (i.e as JAMES MICHAEL SMITH)  and - fullnameCapsEach filed would come out James Michael Smith

the other fields will just be hidden.

I remembered hot to change input to caps in the input field - xfa.event.change  = xfa.event.change.toUpperCase() - but that only works in the input field of course.

i tried setting the fullnameCaps and fullnameCapsEach to equal the rawvalue of the input fullanme field and putting the change code in them - but that doesnt seem to be the answer!

Anyone out there got nay ideas ?

cheers

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

try this solution in the change event of your input field:


var str = xfa.event.newText, capsAll, capsFirst;



  capsAll = str.toUpperCase();


  capsFirst = str.toLowerCase().replace(/([^a-z]|^)([a-z])(?=[a-z]{1})/g, function(_, g1, g2) {


    return g1 + g2.toUpperCase();


    });



fullnameCaps.rawValue = capsAll;


fullnameCapsEach.rawValue = capsFirst;


View solution in original post

3 Replies

Avatar

Correct answer by
Level 10

Hi,

try this solution in the change event of your input field:


var str = xfa.event.newText, capsAll, capsFirst;



  capsAll = str.toUpperCase();


  capsFirst = str.toLowerCase().replace(/([^a-z]|^)([a-z])(?=[a-z]{1})/g, function(_, g1, g2) {


    return g1 + g2.toUpperCase();


    });



fullnameCaps.rawValue = capsAll;


fullnameCapsEach.rawValue = capsFirst;


Avatar

Level 2

Hi

thanks for the suggestion - i'll give that a go.