It is totally unsupported that you are doing. i.e using document.getelementbyid.
you should below approach.
1. create a function which you should call on change of the required field. crmbusiness.wordpress.com/.../crm-2013-javascript-to-get-id-of-record
2. in the function get the current record id and retrieve its attachment using a web api request.
3. if count of attachment is more than 0 - perform your logic or operation.
Please use rest builder to generate your code : github.com/.../CRMRESTBuilder
sample code below :
function GetAttachments()
{
//getid of the record and pass in the request below
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/CurrentEntityPluralSchemaNae?$filter=_objectid_value eq idoftherecord", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var results = JSON.parse(this.response);
for (var i = 0; i < results.value.length; i++) {
var annotationid = results.value[i]["annotationid"];
/// your logic here.
}
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}