Sylvan012
04-24-2007, 10:51 AM
I'm running into the limits of my knowledge.
What I'm trying to do is build a JavaScript function which can accept the name of a <form> and the name of an <input> field as well as the contents of that field and, then, depending on various factors, re-focus the user onto that text field.
The problem is in targeting.
Normally, you just use something like this:
document.formName.fieldName.focus()
However, since I'm passing this data into the function with an onBlur event handler (and storing the data in the function as string variables), I'm not able to target correctly. The page may have many forms on it and the page may have many fields on it. I do not always have control over the name of either. Therefore, I'm using onBlur="javascriptFunctionName(String(this.value),String(this.name),String(this.form.name))" to send the value, <INPUT> field name, and <FORM> name to the function where they are being stored as variables, respectively, : function javascriptFunctionName(elementValue,inputFieldName,inputFormName).
Later on, I use the following, which does not work:
document.form[inputFormName].input[inputFieldName].focus();
I have tried variants:
document.form(inputFormName).input(inputFieldName).focus();
and
document.inputFormName.inputFieldName.focus();
Any idea how to target something using the contents of a variable passed into a function? I'm feeling REALLY stupid right about now...
Yours,
Dave (Sylvan)
What I'm trying to do is build a JavaScript function which can accept the name of a <form> and the name of an <input> field as well as the contents of that field and, then, depending on various factors, re-focus the user onto that text field.
The problem is in targeting.
Normally, you just use something like this:
document.formName.fieldName.focus()
However, since I'm passing this data into the function with an onBlur event handler (and storing the data in the function as string variables), I'm not able to target correctly. The page may have many forms on it and the page may have many fields on it. I do not always have control over the name of either. Therefore, I'm using onBlur="javascriptFunctionName(String(this.value),String(this.name),String(this.form.name))" to send the value, <INPUT> field name, and <FORM> name to the function where they are being stored as variables, respectively, : function javascriptFunctionName(elementValue,inputFieldName,inputFormName).
Later on, I use the following, which does not work:
document.form[inputFormName].input[inputFieldName].focus();
I have tried variants:
document.form(inputFormName).input(inputFieldName).focus();
and
document.inputFormName.inputFieldName.focus();
Any idea how to target something using the contents of a variable passed into a function? I'm feeling REALLY stupid right about now...
Yours,
Dave (Sylvan)