1
Vote

Problems when multiple forms exist on a page

description

If multiple forms exist on a page, and they happen to have elements with the same ID/Name, the code for locating dependentPropertyElement fails. I'd suggest only searching for the dependentProperty within the same form container as the source element.
// error prone lines
var dependentPropertyElement = document.getElementsByName(dependentProperty); // by name
var dependentValue = document.getElementById(dependentProperty).value; // by id

// suggested replacements
var dependentPropertyElement = $(element).closest('form').find('[name="' + dependentProperty +'"]'); // by name
var dependentValue = $(element).closest('form').find('#' + dependentProperty).val(); // by id

comments