Fields Need to be Filled Message to ONLY show upon submit when fields invalid

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Fields Need to be Filled Message to ONLY show upon submit when fields invalid

    This is the code and "fields" is the tag I'm having an issue with since I don't want it to show when the user clicks submit if all the fields are valid:

    // JavaScript Document
    function CheckTheForm() {

    var result = true;
    var msg="";

    document.getElementById('idmail').style.display="n one";
    document.getElementById('fields').style.display="n one";
    document.getElementById('First').style.color='#000 000';
    document.getElementById('maincontactemail').style. color='#000000';
    document.getElementById('Last').style.color='#0000 00';
    document.getElementById('refcode').style.color='#0 00000';



    if (document.validate.First.value.length < 3) {
    document.validate.First.focus();
    document.getElementById('First').style.color="#FF3 333";
    result = false;
    }

    if (document.validate.Last.value.length < 3) {
    document.validate.Last.focus();
    document.getElementById('Last').style.color="#FF33 33";
    result = false;
    }

    if (document.validate.Last.value.length < 3) {
    document.validate.Last.focus();
    document.getElementById('Last').style.color="#FF33 33";
    result = false;
    }

    if (document.validate.refcode.value.length < 3) {
    document.validate.refcode.focus();
    document.getElementById('refcode').style.color="#F F3333";
    result = false;
    }

    if (document.validate.maincontactemail.value.length < 7) {
    document.validate.maincontactemail.focus();
    document.getElementById('maincontactemail').style. color="#FF3333";
    result = false;

    }

    var emailID=document.validate.maincontactemail

    if ((emailID.value==null)||(emailID.value=="")){
    document.validate.maincontactemail.focus();
    document.getElementById('maincontactemail').style. color="#FF3333";
    result = false;
    }
    if ((echeck(emailID.value)==false) && (emailID.value!='')){
    document.validate.maincontactemail.focus();
    document.getElementById('maincontactemail').style. color="#FF3333";
    document.getElementById('idmail').style.display="b lock";
    result = false;


    }


    if(msg==""){
    document.getElementById('fields').style.display="b lock";
    return result;
    }{
    alert(msg)
    return result;

    }
    if(msg==""){
    return result;
    }{
    alert(msg)
    return result;
    }
    }
Working...
X