magritton
11/10/2016 - 10:00 PM

This code gets an element by the title and adds an event handler for onchange.

This code gets an element by the title and adds an event handler for onchange.

function registerCategoriesClick()
    {
        categoryDetailMessage = "";
        var select = document.querySelector('span[title^="389-0288"] input:first-child');
        var categoryDetail = document.querySelector('[title="Category Detail"]');
        var CNPMNPMViolation = document.querySelector("span[title^='CNPM/NPM Violation'] input:first-child");
        var otherViolation = document.querySelector("span[title^='Other Violation'] input:first-child");
        var avoidableExposure = document.querySelector("span[title^='Avoidable Exposure'] input:first-child");
        var documentDetail = document.querySelector("textarea[title$='Description Required Field");

        if(!select.addEventListener)
        {
            select.attachEvent("onclick", categoriesClick);
            CNPMNPMViolation.attachEvent("onclick", categoriesClick);
            otherViolation.attachEvent("onclick", categoriesClick);
            avoidableExposure.attachEvent("onclick", categoriesClick);
            categoryDetail.attachEvent("onfocus", categoryDetailFocus);
            categoryDetail.attachEvent("onblur", categoryDetailBlur);
            categoryDetail.style.color = "#888";
            documentDetail.attachEvent("onfocus", categoryDetailFocus);
            documentDetail.attachEvent("onblur", categoryDetailBlur);
            documentDetail.style.color = "#888";
        }
        else {
            select.addEventListener("click", categoriesClick);
            CNPMNPMViolation.addEventListener("click", categoriesClick);
            otherViolation.addEventListener("click", categoriesClick);
            avoidableExposure.addEventListener("click", categoriesClick);
            categoryDetail.addEventListener("focus", categoryDetailFocus(this));
            categoryDetail.addEventListener("blur", categoryDetailBlur(this));
            categoryDetail.style.color = "#888";
            documentDetail.addEventListener("focus", categoryDetailFocus(this));
            documentDetail.addEventListener("blur", categoryDetailBlur(this));
            documentDetail.style.color = "#888";
        }//end if
    }
function correctiveActionListener()
{
	var select = document.querySelector('select[title="CorrectiveAction"]');
	//console.log(select.Type());
	//select.addEventListener('change',function(){correctiveActionVisibility(select.value)});
	var val = select.value;
	select.setAttribute('onchange','correctiveActionVisibility();');
}

function correctiveActionVisibility()
{
	var select = document.querySelector('select[title="CorrectiveAction"]');
	if(select.value == 'Notified Shop or Code')
	{
		var div = document.getElementById('CorrectiveActionDiv');
		div.style.display = 'block';
	}
	else
	{
		var div = document.getElementById('CorrectiveActionDiv');
		div.style.display = 'none';
	}
}