On 27/05/2005 20:29,
so***********@yahoo.com wrote:
Won't eval return undef if the 'elements' doesn't exist
Which 'elements'? I use that identifier twice in two different ways.
instead of a javascript error?
The eval function won't suppress errors. Both syntax and run-time errors
will result in exceptions.
The only real reason why the code I posted might error out is if there
is no 'main_form' in the document. I don't know why you'd call the
function in this case, but this exceptional condition is detectable as well.
/* group - The name of a group of form controls
* form - The name, index, or id of a form, or
* a reference to a form element
*/
function getElements(group, form) {
/* If the form argument is a string, try
* to find a form with that name or id.
*/
if(('string' == typeof form) || ('number' == typeof form)) {
form = document.forms[form];
}
/* The form variable should now be either
* an object reference or null/undefined.
*/
if(form) {
/* Find all controls within form with
* the name passed via group.
*/
group = form.elements[group];
/* If group is not null, and has a
* string property, type, it is form
* control so insert it into an array.
*
if(group && ('string' == typeof group.type)) {
group = [group];
/* If group is null, no controls were
* found so return an empty array.
*/
} else if(!group) {
group = [];
}
/* In the remaining case (not null and
* no type property), group is a
* collection so return as-is.
*/
} else {
group = [];
}
return group;
}
Mike
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.