Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

passing a control value as argument in a function

Avatar

Level 3

Hi,

I have a procedure that I want to do every time someon exits any of my many text boxes in a form.  Basically, I want the computer to check to see if there are any spaces at the beginning of the entry, and if so, to remove them.

To do that, I wrote a Right() and Left() function, and I want to write another function SpaceTrim() that uses those Right and Left functions to accomplish this.  In general, SpaceTrim() should look something like this:

function

SpaceClear(MyField){

while (left(MyField.rawValue,1) == ' '){

MyField.rawValue

= right(MyField.rawValue,MyField.length - 1);

}

I tried calling this function as SpaceClear(FieldName) and SpaceClear(FieldName.name), and neither would work.  (I didn't really expect that to work, but thought it was worth a try.)

If you want a function to operate on some object that you can specify as an argument to the function, how do you do that?  I'm hoping there's something a little more elegant than changing the object name into a string, passing that string, and then using the eval() command.  But maybe not.

Thanks!

Emily

0 Replies

Avatar

Level 6

u can write using reg. exp. to remove spaces on left and right sides.

In this function strValue is FieldName.rawValue.

// Trims left and right blank spaces
function trim(strValue) {
return strValue.replace(/^\s+|\s+$/g,"");
}

u can also pass FieldName to that function but u have to get rawValue in the function

// Trims left and right blank spaces
function trim(fieldName) {
return fieldName.rawValue.replace(/^\s+|\s+$/g,"");
}

Hope this will help.

RAGHU.