Avoid adding non-existent elements

php code was doing addElements on elements which were not in the HTML
due to Access constraints, leading to JS errors, stuck spinners and an
infinite loop of errors in textarea.js.

php needs to be fixed to prevent this, but if it does happen, this fix
will give graceful error handling.