Home > database >  Document by ID not connecting
Document by ID not connecting

Time:11-29

I was recently working on an assignment for my computer class, but I have a connection error within my code. To my knowledge, the function looks correct.

            function idCard(){
            var firstName = document.getElementByID("firstName").value;
            var lastName = document.getElementByID("lastName").value;
            var address = document.getElementByID("address").value;
            
            document.getElementById("postFullName").innerHTML = firstName   ""   lastName;
            document.getElementById("postAddress").innerHTML = address;
            
            var age = document.getElementByID("age").value;
            var phoneNumber = document.getElementByID("phoneNumber").value;
            
            const numberArray = [age,phoneNumber];
            
            for ( var i = 0; i < numberArray.length; i  ){
                if (numberArray[i]<=100){
                document.getElementId("postAge").innerHTML = numberArray[i];
                }
                else{
                document.getElementId("postPhoneNumber").innerHTML = numberArray[i];
                }
            }
            
            }

The display works fine, and so far I only get one error from my debugging console,"Uncaught TypeError: document.getElementByID is not a function".

CodePudding user response:

In JavaScript, Case sensitivity matters,

first 3 lines after the function, it should be getElementById instead of getElementByID, also 6th, 7th line and inside the for loop

innerHTML should work but its usually used to set html, innerText would be a better option

and good luck with your assignments

  • Related