Todo List Application Code in Pure JavaScript I'd highly appreciate it if you can:


Spot flaws, especially bad practices and suggest a possible alternative method.
Spot inefficiencies and suggest how to perform that task efficiently.
You may review my HTML/CSS as well.




var addRecordFormVisibility = false;
var addRecordForm = document.getElementById('addRecord');
var addRecordFormButton = document.getElementById('submit');
var errors = document.getElementById('errors');
var addRecordFormTrigger = document.getElementById('addRecordFormTrigger');

function prepare() {
    addRecordForm.style.display="none";
}

function triggerAddRecordForm() {
    if(addRecordFormVisibility === false) {
        addRecordForm.style.display="block";
        addRecordFormVisibility = true;
    } else {
        addRecordForm.style.display="none";
        addRecordFormVisibility = false;
    }
}

function submit(event) {
    var userInput = document.getElementById('description').value;

    errors.innerHTML = '';

    if(userInput.length === 0) {
        errors.innerHTML = "Please fill in the form!";
    } else {
        var listItem = document.createElement('li');
        listItem.innerHTML = userInput;

        document.getElementById('todoList').appendChild(listItem);
    }

    event.preventDefault();
}

document.addEventListener("DOMContentLoaded", prepare, false);
addRecordFormButton.addEventListener("click", submit, false);
addRecordFormTrigger.addEventListener("click", triggerAddRecordForm, false);
#todoApplication {
    width: 800px;
    height: 100%;
    margin: 0 auto;
    background: #EEEEEE;
    border: 1px solid #DDDDDD;
    border-radius: 5px;
    padding: 10px;
}
#errors {
    color: red;
}
&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
    &lt;head&gt;
        &lt;meta charset="UTF-8"&gt;
        &lt;title&gt;JavaScript&lt;/title&gt;
        &lt;link rel="stylesheet" href="src/style.css"&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;div id="todoApplication"&gt;
            &lt;button id="addRecordFormTrigger"&gt;Trigger Add Record Form&lt;/button&gt;
            &lt;div id="errors"&gt;

            &lt;/div&gt;
            &lt;form id="addRecord" method="POST"&gt;
                &lt;input id="description" type="text" name="description" placeholder="Enter the task here"&gt;

                &lt;button id="submit"&gt;Submit&lt;/button&gt;
            &lt;/form&gt;
            &lt;ul id="todoList"&gt;&lt;/ul&gt;
        &lt;/div&gt;

        &lt;script src="src/TodoApp.js"&gt;&lt;/script&gt;
    &lt;/body&gt;
&lt;/html&gt;
Ok so, your code is overall looking nice, but a few changes could be made:



It's important to make sure you leave whitespace around your operators, like:


addRecordForm.style.display="none";
                           ^^



Could use whitespace around the operators.



I try not to suggest ternaries very often, but I believe that triggerAddRecordForm could be simplified with the use of one.


function triggerAddRecordForm() {
    if(addRecordFormVisibility === false) {
        addRecordForm.style.display="block";
        addRecordFormVisibility = true;
    } else {
        addRecordForm.style.display="none";
        addRecordFormVisibility = false;
    }
}



into:

function triggerAddRecordForm() {
    addRecordForm.style.display = addRecordFormVisiblity ? "none" : "block";
    addRecordFormVisibility = !addRecordFormVisibility;
}


On the subject of triggerAddRecordForm(), in general you shouldn't compare to false, then else it. You should leave the check empty (checks if the variable is true) like so:

if(addRecordFormVisibility) {
    doStuff();
} else {
    doOtherStuff();
}




In submit(), you could improve errors.innerHTML = ''.
Why don't you just set errors to document.getElementById('errors').innerHTML instead, seeing as you don't use errors other than for that?

In submit() you should also improve your line spacing as well, as it seems a little strange.