I have a form field (a series of flags) that is created dynamically from the database, so it is possible that this field will not exist on the form (if the database does not have the corresponding values). I have code that needs to be executed based on whether a field exists, and pull out the values ββthat are selected if they exist. I cannot get javascript to recognize that this field exists. Here is what I tried:
function displayAction(){ var f = document.adminForm; var a = f.action; if(f.prefix.value!="-") { a = a + '&task=callExclusionDisplay&prefix=' + f.prefix.value; } else { var exclusions = document.getElementById("exclusions"); if (exclusions != null){ alert("exclusions set"); a = a + '&task=callExclusionCreate&prefix=' + f.prefix.value + '&exclusions=' + exclusions.join(); } } alert('after if, action is ' + a); }
The code never passes an if statement that checks if an exception is an exception, although when viewing a page there are several flags with exception names (with an identifier also set for exceptions). Is there a problem with! = Null because it is a group of checkboxes and not a single form element? How can I make this work? If I skip the null test, the code throws exception errors that are not detected if the database does not return any corresponding values.
EmmyS source share