form validation issue
<p>Hi i am doing the form validation using core javascript. in which i wrote this function. According to the function i need to enable the error message, if the value is empty. and i given the same style of stuff on all three name field, company field, and message field.</p>

<p>my function works fine. but it is just enabling the name field error alone, while i give submit button eventhough rest company field and message fields are empty. any one help me? why my function not enabling all three error message?</p>

<pre><code>window.onload = function (){
    var subButton = document.getElementById("submit");
    subButton.onclick = function (){
        var myForm = document.getElementsByTagName('form')[0];
        myElements = myForm.elements;
            for(i=0;i&lt;myElements.length;i++){
                ele = myElements[i];
                if(ele.type == 'text' || ele.type == 'textarea'){
                    switch(ele.id){
                        case 'name':
                        case 'company':
                        case 'message':
                            var text = ele.value;  
                            var textInfo = textValidation(text);
                            if(textInfo){
                                while(ele.nextSibling &amp;&amp; ele.nextSibling.nodetype != 1){
                                    ele = ele.nextSibling;
                                    ele.nextSibling.style.display = 'block';    
                                }
                            }

                        break;
                        case 'email': 
                        ele.style.border = '1px solid green';
                        break;
                        case 'phone': 
                        ele.style.border = '1px solid blue';
                        break;
                        default :
                        return false;   
                    }



                }
                function textValidation (text){
                    return !/[^\s]/.test(text); 
                }
            }
        }
    }
</code></pre>

<p>Here is my HTML code what i am using :</p>

<pre><code> &lt;form action="#" method="#" id="contact-form"&gt;
                        &lt;fieldset&gt;
                            &lt;legend&gt;Contact TWG online&lt;/legend&gt;
                            &lt;label&gt;YOUR NAME&lt;/label&gt;
                            &lt;input id="name" type="text"  /&gt;
                            &lt;span class="error"&gt;Fill the name!&lt;/span&gt;
                            &lt;label&gt;YOUR EMAIL ADDRESS&lt;/label&gt;
                            &lt;input id="email" type="text" /&gt;
                            &lt;span class="error"&gt;Fill the Email!&lt;/span&gt;
                            &lt;label&gt;YOUR TELEPHONE NUMBER&lt;/label&gt;
                            &lt;input id="phone" type="text" /&gt;
                             &lt;span class="error"&gt;Fill the Phone Number!&lt;/span&gt;
                            &lt;label&gt;YOUR COMPANY&lt;/label&gt;
                            &lt;input id="company" type="text" /&gt;
                             &lt;span class="error"&gt;Fill the Company name!&lt;/span&gt;
                            &lt;label&gt;YOUR MESSAGE&lt;/label&gt;
                            &lt;textarea id="message"&gt;&lt;/textarea&gt;
                             &lt;span class="error"&gt;your message is needed&lt;/span&gt;
                            &lt;input type="button" id="submit" value="send message" /&gt;
                        &lt;/fieldset&gt;
                    &lt;/form&gt;
</code></pre>

<p>Thanks for advance.</p>
