Pass form elements by reference to function

Is it possible to pass form elements by reference to function?
I want to create a function that changes form element’s text attribute (replaces some chars…) and I want to call it from different form elements.

here is the function (it replaces ‘~~’ to ‘\n’ in text strings):

function addLineBreaks(formElement) {
formElement.text.replace(/~~/gi, “\n”);
}

and I want to be able call it like this:
addLineBreaks($w(‘#text1’);
addLineBreaks($w(‘#text2’);
etc…
and that $w(‘#text1’).text & $w(‘#text2’).text in this example will be changed accordignly.

it’s not working that way.
What is the correct way do it?

thanks,
Gal

Function goes

function addLineBreaks(formElementId) {
   $w("#"+formElementId).text.replace(/~~/gi, "\n");
}

Call it using

addLineBreaks('text1');

Thanks!!
Simpler than I thought… no need to pass by reference…

however I had to change the statement in the function to:

$w(“#”+formElementId).text = $w(“#”+formElementId).text.replace(/~~/gi, “\n”);