This topic is locked

Replace special chars in javascript

8/12/2020 8:23:18 AM
PHPRunner General questions
R
RogerN author

Hi all.
I'm using this Javascript to autopopulate ctrlField4 with info from field 1 and 2 in function OnPageLoad. What i need is a way to replace special chars at the same time.

Anyone have any idea to acomplish this?

var ctrlField1 = Runner.getControl(pageid, 'givenName');

var ctrlField2 = Runner.getControl(pageid, 'sn');

var ctrlField3 = Runner.getControl(pageid, 'cn');

var ctrlField4 = Runner.getControl(pageid, 'userPricipalName');
function func() {

ctrlField3.setValue(ctrlField1.getValue() + " " + ctrlField2.getValue());

ctrlField4.setValue(ctrlField1.getValue() + "." + ctrlField2.getValue());

};

ctrlField2.on('keyup', func);

ctrlField3.on('keyup', func);
Myr0n 8/12/2020

You can use replace string here is an example how I am using it.
the label MovementTypeId02 has some value like this "Did you check the results
of the <b>|ZipCode|</b> zip code well?"

var ctrlZipCode = Runner.getControl(pageid,'ZipCode');

confirmMessage = Runner.getCustomLabel('MovementTypeId02');

confirmMessage = confirmMessage.replace('|ZipCode|',ctrlZipCode.getValue());



the output is:

Did you check the resultsof the 90210 zip code well?

notice that the replace function will find the word "|ZipCode|" and replace by the value in ctrlZipCode.getValue()