title: validation form in table mode with javascript
body: <p>i made my form in table mode
   like this:</p>
  
  <pre><code>&lt;form name="register" method="post" action="#" onSubmit="return validasi()"&gt;         
      &lt;table width="507" border="0"&gt;
        &lt;h1 class="title"&gt;&lt;a href="#"&gt;Form Perubahan Password&lt;/a&gt;&lt;/h1&gt;
          &lt;tr&gt;
            &lt;td width="190" &gt;&lt;span id="usernameerror" class="style20"&gt;Masukkan Username &lt;/span&gt;&lt;/td&gt;
            &lt;td width="319"&gt;&lt;input name="username" type="text"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;&lt;span id="passworderror" class="style20"&gt;Masukkan Password Lama&lt;/span&gt;&lt;/td&gt;
            &lt;td&gt;&lt;input name="pass" type="password"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;&lt;span id="password1error" class="style20"&gt;Masukkan Password Baru&lt;/span&gt;&lt;/td&gt;
            &lt;td&gt;&lt;input name="pass1" type="password"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;&lt;span id="password2error" class="style20"&gt;Ulangi Masukkan Password Baru&lt;/span&gt;&lt;/td&gt;
            &lt;td&gt;&lt;input name="pass2" type="password"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&lt;/td&gt;
            &lt;td&gt;&lt;input type="submit" name="Submit" value="Submit"&gt;
            &lt;input type="reset" name="reset" value="Reset"&gt;&lt;/td&gt;
          &lt;/tr&gt;
        &lt;/table&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>and this my validation code with javascript. check it out..</p>
  
  <pre><code>&lt;script language="javascript"&gt;
   function checkName(register)
  
      {
          var eobj = document.getElementById('usernameerror');        
          var susername = register.username.value;        
          var oRE = /^[a-z0-9]+[_.-]?[a-z0-9]+$/i;        
          var error = false;        
          eobj.innerHTML = '';        
          if (susername == '') {
  
              error = 'Error: Username tidak boleh kosong';        
              register.username.focus();
          }
           else if (!oRE.test(susername))  
  
      {  
        error="Salah format";  
      }  
          if (error)        
          {
              register.username.focus();        
              eobj.innerHTML = error;        
              return false;
          }        
          return true;
      }
      function validatePwd(register) /* old password verification */
      {
          var eobj = document.getElementById('passworderror');
          var invalid = ' ';
          var pw = register.pass.value;
          var error = false;
          eobj.innerHTML = '';
          if (pw.length &lt; 1)
  
          {
              error = 'Masukkan password anda';
          } 
          else if (pw.indexOf(invalid) &gt; -1)
          {
              error = 'Anda harus mengisi password';
          }
          if (error)
          {
              register.pass.focus();
              eobj.innerHTML = error;
              return false
          }
             return true;
      }
      function validatePwd1(register) /* password &amp; retype-password verification */
  
      {
  
          var eobj1 = document.getElementById('password1error');        
          var eobj2 = document.getElementById('password2error');        
          var invalid = ' ';        
          var pw1 = register.pass1.value;        
          var pw2 = register.pass2.value;        
          var error = false;        
          eobj1.innerHTML = '';        
          eobj2.innerHTML = '';        
          if (pw1.length &lt; 1)
  
          {
                error = 'Masukkan password anda';
  
          } 
          else if (pw1.indexOf(invalid) &gt; -1)
  
          {
                error = 'Anda harus mengisi password';
  
          }        
          if (error)
  
          {
  
              register.pass1.focus();        
              eobj1.innerHTML = error;        
              return false
  
          }
  
          if (pw1 != pw2)
  
          {
                      eobj2.innerHTML = ' password tidak sama, coba masukkan kembali password anda';        
              return false;
  
          }
                  return true;
  
      }
  
  
      function validasi()
  
      {
  
          var form = document.forms['register'];        
          var ary = [checkName, validatePwd, validatePwd1];        
          var rtn = true;        
          var z0 = 0;        
          for (var z0 = 0; z0 &lt; ary.length; z0++)
  
          {        
              if (!ary[z0](form))
  
              {        
                  rtn = false;        
              }        
          }
          return rtn;
           }
  &lt;/script&gt;
  </code></pre>
  
  <p>When i use this validation in usually form its work But in table mode that's validation code doesn't work..help me to solve this problem...tq</p>
  
  <p>view demo
  <a href="http://jsfiddle.net/andricoga/u9eZz/" rel="nofollow">http://jsfiddle.net/andricoga/u9eZz/</a></p>