0

This script var AllObjects = document.forms[0].all is throwing error like undefined.

Can someone guide me how to rewrite this? Thank you

function SubmitTheForm(button) {
    var selectBox;
    PleaseWait();
    var AllObjects = document.forms[0].all;
    var requiredFields = document.getElementById('RequiredFieldsLabel').innerText;
    for (i = 0; i < AllObjects.length; i++) {
        if (AllObjects[i].className === 'Mandatory') {
            if (AllObjects[i].type === "text" && trim(AllObjects[i].value) === '') {
                return false;
            }
            else if ((AllObjects[i].type === "select-multiple" || AllObjects[i].type === "select-one") && AllObjects[i].style.display !== 'none' && AllObjects[i].options.length === 0)
                return false;
            }
            else if (AllObjects[i].type === "select-one" && AllObjects[i].value === "") {                 
                return false;
            }
        }
    }
function PleaseWait() {
    displayAnimationIn($("body"), "", "loading-80.gif");
}
Learning
  • 13
  • 3
  • 1
    if you want to get all `input` elements, you could do `var AllObjects = document.forms[0].getElementsByTagName("input");` – GrafiCode Jul 05 '22 at 08:46
  • @GrafiCode, could you please tell me what this line does `document.forms[0].all` – Learning Jul 05 '22 at 08:53
  • 1
    as far as I know, there's no `.all` property / method for `form` elements, so this `document.forms[0].all` gives null – GrafiCode Jul 05 '22 at 08:57

0 Answers0