How I pass a field name parameter in Javascript?

I have this code (below) that won’t work. I am trying to use it on the OnChange event of a one field, so that it changes the date of ANOTHER field (LastUpdatedField). Any ideas.

Thanks!!

Luis

function ChangeDate(LastUpdatedField) {

document.forms[0].LastUpdatedField.value=Date()

}

Subject: How I pass a field name parameter in Javascript?

As long as you are calling that function with the fieldname in question being passed in as a string, then it should work.

eq:

ChangeDate(“LastUpdated”);

Subject: How I pass a field name parameter in Javascript?

document.forms[0].LastUpdatedField.value = document.forms[0].TheFieldThatJustChanged.value;

Subject: Solved: How I pass a field name parameter in Javascript?

Solution (Thanks to all):

Steve was correct. This worked for me:

function LastUpdate(fld){

var fldName = eval(‘document.forms[0].’ + fld);

fldName.value = Date();

}

And you call it using:

LastUpdate(“FieldName”);

This function is handy for changing a field to hold the date that another field was changed.

Luis

Subject: How I pass a field name parameter in Javascript?

¡Hola! :wink:

You may want to use the “eval” function. Something like:

function ChangeDate(fld){

var fldName = eval(‘document.forms[0]’ + fld);

fldName.value = Date();

};

(I didn’t test it)

What type of field are you trying to call this from? Is it an editable field or a listbox? Have you tried it in the “onBlur” event (i.e. when exiting)? Try it in different events after using the “eval” function.

Good luck!

Steve in Montreal

“It hurts to be on the cutting edge.”