Verifying that all form fields are filled in I grabbed the form from some random site because I'm only interested writing the javascript at the moment.

I am trying to check that a user has selected or entered text for all fields. I've made it a long if if-else but that can't be the best/most elegant/easiest solution.

Leaving aside the radio button validation for now, what's the better way to check that the text fields, drop down, and checkboxes all have a value/input?

I'm teaching myself javascript so I'm open to being told the proper way and I'll research it and do it on my own, or updating my fiddle would be fine too. (Be gentle with me. I'm sure this code is janky.)

Any thoughts on this would be appreciated.

Fiddle: https://jsfiddle.net/kiddigit/g0rur21a/

document.getElementById("newForm").addEventListener("submit", enterForm);

function enterForm(event) {
    event.preventDefault();

    var dropdown = document.getElementById('dropDown');

    if (document.getElementById('fname').value === ''){ 
            document.getElementById('fname').focus(); 
            alert('Enter text.');
        } else if (document.getElementById('eMail').value === ''){
            document.getElementById('eMail').focus();
            alert('Enter text.');
            } else if  (document.getElementById('textArea').value === '') {
                document.getElementById('textArea').focus();
                alert('Enter text.');
                } else if (!dropDown.value) {
                    document.getElementById('dropDown').focus();
                    alert('Choose an option.');
                    } else if ( ( newForm.checkbox[0].checked == false ) &amp;&amp; ( newForm.checkbox[1].checked == false ) ) 
                        { alert ( "Please choose a checkbox" ); 
                            return false;
                            }

    var radios = document.getElementsByName("radio");
    var formValid = false;
    var i = 0;
    while (!formValid &amp;&amp; i &lt; radios.length) {
        if (radios[i].checked) formValid = true;
            i++;        
        }

        if (!formValid) alert("Please check a radio button.");
        return formValid;

        return false;
};
Couple of suggestions from my end.

1 > There is a better way to check null or empty in javascript,this can be done more efficiently with this

 if (document.getElementById('fname').value)
 {
   //value exists.
 }


Above condition evaluates to true if value is not equal to any of the following:


null 
undefined 
NaN 
empty string ("") 
0 
false


2 > Try to use switch case instead of so many if else.It will make your code more elegant and readable.

3 > Take care of indentation currently it's not very good.

4 > Instead of writing ewForm.checkbox[0].checked == false you can use

if(!ewForm.checkbox[0].checked) 
{
//not checked
}