Click to See Complete Forum and Search --> : Setting Focus to a variable


nbenton99
12-17-2003, 01:59 PM
Hi I'm trying to dynamically set focus to a form element. Here is what I have.


function isDate(val,format,formField) {
var date=getDateFromFormat(val,format);
if (date==0) {

alert("this is " + formField +" has a wrong date");
//document.CurrentForm."formField".focus();
//document.CurrentForm.ItemAddedOnDate.focus();
document.CurrentForm.focus('formField');

return false;
}
else {
alert("this is a right date");

return true;
}
}

I've tried test it a few ways I know my variable "formField" has the right value because I have added it into the alert and it is displayed fine and I know that my focus works when I hard code the form field name "ItemAddedOnDate", however I can't for the life of me get it to work if I put the variable formfield in the focus. Does anyone have anyidea what I'm doing wrong or how I can get this to work.

TIA

Nikki

requestcode
12-17-2003, 02:35 PM
Try this:
document.CurrentForm.elements[formField].focus();

nbenton99
12-17-2003, 03:02 PM
Thank you

I feel much better now.

That works great!!!