I have encountered an issue when trying to target multiple IDs with JavaScript in order to disable input fields associated with them. The script I am using seems straightforward, but I noticed that on pages where the middle element is missing, the third one does not get disabled (it appears as though the script stops working if the second element is not found).
<script>
document.getElementById("id_1").disabled = true;
document.getElementById("id_2").disabled = true;
document.getElementById("id_3").disabled = true;
</script>
On pages where all three IDs are present, the script functions correctly. However, on pages where either "id_1" or "id_2" is absent, the remaining elements are not disabled even if they exist.
Is there a workaround for this issue? Please note that creating separate scripts for each page is not feasible, as this code will be placed in the footer, which is consistent across all pages.
Thank you!