title: Javascript validation with default field value
body: <p>newbie here. I need some help.</p>
  
  <p>I am using a pre-written javascript form validator for my website but the thing is, it is not designed for fields with <strong>default value</strong>. So the problem is the validator is considering the value "Name" and "Message" to be valid and the message goes through without any error message.</p>
  
  <p>I did some research and saw some suggestions but with very little knowledge in javascript i don't know how to implement them or how to create another set of validation rules.</p>
  
  <p>By the way i am using free contact form from [http://www.faridhadi.com/][1]</p>
  
  <p>Below is the script i am working on:</p>
  
  <p>I hope you guys can help me! Thanks!</p>
  
  <pre><code>// JavaScript Document
  
  $(document).ready(function() {
  
      $('#contactForm #submit').click(function() {
          // Fade in the progress bar
          $('#contactForm #formProgress').hide();
          $('#contactForm #formProgress').html('&lt;img src="images/ajax-loader.gif" /&gt; Sending&amp;hellip;');
          $('#contactForm #formProgress').fadeIn();
  
          // Disable the submit button
          $('#contactForm #submit').attr("disabled", "disabled");
  
          // Clear and hide any error messages
          $('#contactForm .formError').html('');
  
          // Set temaprary variables for the script
          var isFocus=0;
          var isError=0;
  
          // Get the data from the form
          var name=$('#contactForm #name').val(); 
          var email=$('#contactForm #email').val();
          var subject=$('#contactForm #subject').val();
          var message=$('#contactForm #message').val();
  
          // Validate the data
          if(name=='') {
              $('#contactForm #errorName').html('This is a required field.');
              $('#contactForm #name').focus();
              isFocus=1;
              isError=1;
          }
          if(email=='') {
              $('#contactForm #errorEmail').html('This is a required field.');
              if(isFocus==0) {
                  $('#contactForm #email').focus();
                  isFocus=1;
              }
              isError=1;
          } else {
              var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
              if(reg.test(email)==false) {
                  $('#contactForm #errorEmail').html('Invalid email address.');
                  if(isFocus==0) {
                      $('#contactForm #email').focus();
                      isFocus=1;
                  }
                  isError=1;
              }
          }
          if(message=='') {
              $('#contactForm #errorMessage').html('This is a required field.');
              if(isFocus==0) {
                  $('#contactForm #message').focus();
                  isFocus=1;
              }
              isError=1;
          }
  
          // Terminate the script if an error is found
          if(isError==1) {
              $('#contactForm #formProgress').html('');
              $('#contactForm #formProgress').hide();
  
              // Activate the submit button
              $('#contactForm #submit').attr("disabled", "");
  
              return false;
          }
  
          $.ajaxSetup ({
              cache: false
          });
  
          var dataString = 'name='+ name + '&amp;email=' + email + '&amp;subject=' + subject + '&amp;message=' + message;  
          $.ajax({
              type: "POST",
              url: "php/submit-form-ajax.php",
              data: dataString,
              success: function(msg) {
  
                  //alert(msg);
  
                  // Check to see if the mail was successfully sent
                  if(msg=='Mail sent') {
                      // Update the progress bar
                      $('#contactForm #formProgress').html('&lt;img src="images/ajax-complete.gif" /&gt; Message sent.').delay(2000).fadeOut(400);
  
                      // Clear the subject field and message textbox
                      $('#contactForm #subject').val('');
                      $('#contactForm #message').val('');
                  } else {
                      $('#contactForm #formProgress').html('');
                      alert('There was an error sending your email. Please try again.');
                  }
  
                  // Activate the submit button
                  $('#contactForm #submit').attr("disabled", "");
              },
              error: function(ob,errStr) {
                  $('#contactForm #formProgress').html('');
                  alert('There was an error sending your email. Please try again.');
  
                  // Activate the submit button
                  $('#contactForm #submit').attr("disabled", "");
              }
          });
  
          return false;
      });
  });
  </code></pre>