0

I'm getting can't read property 'elements'of undefined error when I run the following code at the below line:

retrieveURL('<%=request.getContextPath()%>/MatchingRules.action?matchFormAction=5&code=' + thisElem.value, 'matchForm');

    function enableRadio(thisElem) {
        alert(thisElem.value)
        var divname = thisElem.value + '_div';
        var divname1 = thisElem.value + '_div1';
        if (thisElem.checked) {
            if (document.getElementsByName(thisElem.value).length != 0) {
                document.getElementsByName(thisElem.value)[0].disabled = false;
                document.getElementsByName(thisElem.value)[1].disabled = false;
                document.getElementsByName(thisElem.value)[2].disabled = false;
            }
            retrieveURL('<%=request.getContextPath()%>/MatchingRules.action?matchFormAction=5&code=' + thisElem.value, 'matchForm');

            if (document.getElementsByName(thisElem.value).length != 0) {
                document.getElementsByName(thisElem.value)[1].checked = true;
                retrieveURL('<%=request.getContextPath()%>/MatchingRules.action?matchFormAction=7&code=' + thisElem.value, 'matchForm');
            }

        } else {

            if (document.getElementsByName(thisElem.value).length != 0) {
                document.getElementsByName(thisElem.value)[0].disabled = true;
                document.getElementsByName(thisElem.value)[0].checked = false;
                document.getElementsByName(thisElem.value)[1].disabled = true;
                document.getElementsByName(thisElem.value)[1].checked = false;
                document.getElementsByName(thisElem.value)[2].disabled = true;
                document.getElementsByName(thisElem.value)[2].checked = false;
                $(divname).style.visibility = 'hidden';
                $(divname1).style.visibility = 'hidden';
            }
            retrieveURL('<%=request.getContextPath()%>/MatchingRules.action?matchFormAction=6&code=' + thisElem.value, 'matchForm');
            if (document.getElementsByName(thisElem.value)[0].checked) {
                //retrieveURL('<%=request.getContextPath()%>/MatchingRules.action?matchFormAction=12&code='+thisElem.value, 'matchForm');
                document.getElementsByName(thisElem.value)[0].disabled = true;
                document.getElementsByName(thisElem.value)[0].checked = false;
            }

            if (document.getElementsByName(thisElem.value)[1].checked) {
                //retrieveURL('<%=request.getContextPath()%>/MatchingRules.action?matchFormAction=12&code='+thisElem.value, 'matchForm');
                document.getElementsByName(thisElem.value)[1].disabled = true;
                document.getElementsByName(thisElem.value)[1].checked = false;
            }

            if (document.getElementsByName(thisElem.value)[2].checked) {
                //retrieveURL('<%=request.getContextPath()%>/MatchingRules.action?matchFormAction=12&code='+thisElem.value, 'matchForm');
                document.getElementsByName(thisElem.value)[2].disabled = true;
                document.getElementsByName(thisElem.value)[2].checked = false;
            }


        }
    }
Snirka
  • 602
  • 1
  • 5
  • 19
  • The problem seems to actually be in your `retrieveURL` function and when you call it, you get an error, so we'd need to see that function but most likely it's just that `<%=request.getContextPath()%>/MatchingRules.action?matchFormAction=5&code=' + thisElem.value, 'matchForm'` isn't resulting in what you think it does. Start by checking that value. – Scott Marcus Jun 26 '21 at 15:22
  • Also, [don't use `getElementsByName()`](https://stackoverflow.com/questions/54952088/how-to-modify-style-to-html-elements-styled-externally-with-css-using-js/54952474#54952474) and indexes. Instead, use [`.querySelectorAll()`](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll). – Scott Marcus Jun 26 '21 at 15:22
  • The code you have provided does not reference `elements` anywhere. – trincot Jun 26 '21 at 15:23

0 Answers0