I need help with javascript client-side validation

  • bido
  • Newbie
  • Newbie
  • bido
  • Posts: 6

Post 3+ Months Ago

I have problem with my javascript form validation... Validation works only on last question and I can't understand why it doesn't work on other questions..

Html code :
Code: [ Select ]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "----">
<html xmlns="---/1999/xhtml">
<head>
<script type="text/javascript" src="script.js"></script>



<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Questionaire</title>
<link href="oneColLiqCtrHdr19.css" rel="stylesheet" type="text/css" />

<style type="text/css">
<!--
body {
    background-color: #FFF;
    background-image: url(images/aa.jpg);
}
-->
</style></head>

<body class="oneColLiqCtrHdr">
<div id="container">
<div id="header">
  <h1>&nbsp;</h1></div>

  
   <!-- forms -->
   
   
   
 <form action="---/saveforminfo.aspx" method="post" onsubmit="return checkform(this);" >
   
 <input type="hidden" name="surveyid" value="knjuku" />
 <input type="hidden" name="usecookie" value="true" />
 <input type="hidden" name="landingpage" value="---.html" /> 
 
<p align="center"><b>This survey was made not for FDIM.</b></p>
  <p>

<b>Please enter your personal information</b>
 
  </p>
  <p><b>Your Occupation:</b>
   <input type="text" name="occupation" />
  </p>
  <p><b>Age Group:</b>
   <select name="age">
    <option value="under 18">less then 18</option>
    <option value="18-25">18-25</option>
    <option value="26-35">26-35</option>
    <option value="over 35">more then 35</option>
   </select>
  
  </p>
  <p><b>Status:</b>
   <select name="status">
    <option value="single">Single</option>
    <option value="single with children">Single with children</option>
    <option value="in relationship">In relationship</option>
    <option value="married">Married</option>
    <option value="divorced">Divorced</option>
   </select>
  </p>
  <p><b>Gender:</b>
   <input type="radio" name="gender" value="male" /> Male
   <input type="radio" name="gender" value="female" /> Female
  
  </p>
  <p><b>Do you have a job?</b>
   <input type="radio" name="job" value="yes" />Yes
   <input type="radio" name="job" value="no" />No 
  
  </p>
  <p>&nbsp;</p>
   <p>
    <!-- 1 vopros -->
</p>
   <p><b>1. Why do You use online social media?</b>
    
    
    </p>
  <p>
   <input type="radio" name="bla" value="To chat with friends" />
   To chat with friends<br></br>
   <input type="radio" name="bla" value="To read news" /> To read news<br></br>
   <input type="radio" name="bla" value="To write blogs" /> To write blogs<br></br>
   <input type="radio" name="bla" value="Other" /> Other<br></br>
   
  </p>
  <p>
   <!-- 2 vopros -->
     
   <b>2. What online social media do You use more often?</b>
  </p>
   
  <p>&nbsp; </p>
  <p>
   <select name="more">
      
      <option value="MySpace">MySpace</option>
      <option value="Twitter">Twitter</option>
      <option value="Facebook">Facebook</option>
      <option value="LinkedIn">LinkedIn</option>
   </select> 
  </p>
  <p>&nbsp;</p>   
    
    <!-- 3 vopros -->
              
     <b>3. When do You use it?</b>
  <p>
    <input type="radio" name="use" value="1" /> At home<br></br>
    <input type="radio" name="use" value="2" /> At work<br></br>
    <input type="radio" name="use" value="3" /> At school<br></br>
    <input type="radio" name="iuse" value="4" /> In the bus/train<br></br>
    <input type="radio" name="use" value="5" /> Other<br></br>
   
  </p>
    <p><b>4. How much hours approximately do You spend on social media?</b>
    </p>
     <select name="hours">
     
      <option value="less than 2 hours">less than 2 hours a day</option>
      <option value="2-4 hours">2-4 hours a day</option>
      <option value="4-8 hours">4-8 hours a day</option>
      <option value="8-12 hours">8-12 hours a day</option>
      <option value="more than 12 hours">more than 12 hours a day</option>
     </select> 
     
   
  <p>&nbsp;</p>
    
      
      <p>
      <!-- 5 vopros -->
      
      <b>5. Do You use social media often?</b></p>
      <p>
     
      <input type="radio" name="often" value="Yes" />
      Yes
    <input type="radio" name="often" value="No" /> No
     
      
      <!-- 6 vopros -->
      </p>
      <p><b>6. Social Media website to which You usually upload</b></p>
  <p>
     <input type="radio" name="upload" value="Youtube" /> Youtube<br></br>
    <input type="radio" name="upload" value="Flickr" /> Flickr<br></br>
    <input type="radio" name="upload" value="Photobucket" /> Photobucket<br></br>
    <input type="radio" name="upload" value="Slideshare" /> Slideshare<br></br>
    <input type="radio" name="upload" value="Other" /> Other 
  </p>
   
     <!-- 7 vopros -->
     
    <b>7. Where do You chat with Your friends</b>
  
  <select name="chatting">
    
   <option value="Msn">Msn</option>
    <option value="Skype">Skype</option>
    <option value="Yahoo!">Yahoo!</option>
    <option value="Other">Other</option>
  </select>
  <p>&nbsp;</p>
 
  
   
   <!-- 8 vopros -->

 <b>8. You use social media for</b>  
  
   
   <select name="using">
    
    <option value="Personal reasons">Personal reasons</option>
    <option value="Professional reasons">Professional reasons</option>
    <option value="Don't use it">Don't use it</option> 
   </select>
   
  <p>&nbsp;</p>

 
 
  <p>
   <!-- 9 vopros -->
   
   <b>9. You prefer to obtain the information You need at</b> 
   
   
   <select name="information">
    
    <option value="Yahoo!">Yahoo!</option>
    <option value="Google">Google</option>
    <option value="Wikipedia">Wikipedia</option>
    <option value="Ask">Ask</option>
    <option value="Other">Other</option> 
   </select>
  </p>
  
   
   
   <!-- 10 vopros -->
   
   <b>10. What do You prefer to do being online</b>?
  
   
   <select id="drop" name="online">
    <option value="Read blogs">Read blogs</option>
    <option value="Chat with friends">Chat with friends</option>
    <option value="Watch videos">Watch videos</option>
    <option value="Read news">Read news</option>
    <option value="Other">Other</option> 
   </select>
  
  
  <!-- konec voprosov -->
  
  <!-- button-submit -->
  <p align="center">
 <input type="submit" value="Submit" />
 </p>
 </form>
<!-- end #container -->
</div>
</body>
</html>
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "----">
  2. <html xmlns="---/1999/xhtml">
  3. <head>
  4. <script type="text/javascript" src="script.js"></script>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>Questionaire</title>
  7. <link href="oneColLiqCtrHdr19.css" rel="stylesheet" type="text/css" />
  8. <style type="text/css">
  9. <!--
  10. body {
  11.     background-color: #FFF;
  12.     background-image: url(images/aa.jpg);
  13. }
  14. -->
  15. </style></head>
  16. <body class="oneColLiqCtrHdr">
  17. <div id="container">
  18. <div id="header">
  19.   <h1>&nbsp;</h1></div>
  20.   
  21.    <!-- forms -->
  22.    
  23.    
  24.    
  25.  <form action="---/saveforminfo.aspx" method="post" onsubmit="return checkform(this);" >
  26.    
  27.  <input type="hidden" name="surveyid" value="knjuku" />
  28.  <input type="hidden" name="usecookie" value="true" />
  29.  <input type="hidden" name="landingpage" value="---.html" /> 
  30.  
  31. <p align="center"><b>This survey was made not for FDIM.</b></p>
  32.   <p>
  33. <b>Please enter your personal information</b>
  34.  
  35.   </p>
  36.   <p><b>Your Occupation:</b>
  37.    <input type="text" name="occupation" />
  38.   </p>
  39.   <p><b>Age Group:</b>
  40.    <select name="age">
  41.     <option value="under 18">less then 18</option>
  42.     <option value="18-25">18-25</option>
  43.     <option value="26-35">26-35</option>
  44.     <option value="over 35">more then 35</option>
  45.    </select>
  46.   
  47.   </p>
  48.   <p><b>Status:</b>
  49.    <select name="status">
  50.     <option value="single">Single</option>
  51.     <option value="single with children">Single with children</option>
  52.     <option value="in relationship">In relationship</option>
  53.     <option value="married">Married</option>
  54.     <option value="divorced">Divorced</option>
  55.    </select>
  56.   </p>
  57.   <p><b>Gender:</b>
  58.    <input type="radio" name="gender" value="male" /> Male
  59.    <input type="radio" name="gender" value="female" /> Female
  60.   
  61.   </p>
  62.   <p><b>Do you have a job?</b>
  63.    <input type="radio" name="job" value="yes" />Yes
  64.    <input type="radio" name="job" value="no" />No 
  65.   
  66.   </p>
  67.   <p>&nbsp;</p>
  68.    <p>
  69.     <!-- 1 vopros -->
  70. </p>
  71.    <p><b>1. Why do You use online social media?</b>
  72.     
  73.     
  74.     </p>
  75.   <p>
  76.    <input type="radio" name="bla" value="To chat with friends" />
  77.    To chat with friends<br></br>
  78.    <input type="radio" name="bla" value="To read news" /> To read news<br></br>
  79.    <input type="radio" name="bla" value="To write blogs" /> To write blogs<br></br>
  80.    <input type="radio" name="bla" value="Other" /> Other<br></br>
  81.    
  82.   </p>
  83.   <p>
  84.    <!-- 2 vopros -->
  85.      
  86.    <b>2. What online social media do You use more often?</b>
  87.   </p>
  88.    
  89.   <p>&nbsp; </p>
  90.   <p>
  91.    <select name="more">
  92.       
  93.       <option value="MySpace">MySpace</option>
  94.       <option value="Twitter">Twitter</option>
  95.       <option value="Facebook">Facebook</option>
  96.       <option value="LinkedIn">LinkedIn</option>
  97.    </select> 
  98.   </p>
  99.   <p>&nbsp;</p>   
  100.     
  101.     <!-- 3 vopros -->
  102.               
  103.      <b>3. When do You use it?</b>
  104.   <p>
  105.     <input type="radio" name="use" value="1" /> At home<br></br>
  106.     <input type="radio" name="use" value="2" /> At work<br></br>
  107.     <input type="radio" name="use" value="3" /> At school<br></br>
  108.     <input type="radio" name="iuse" value="4" /> In the bus/train<br></br>
  109.     <input type="radio" name="use" value="5" /> Other<br></br>
  110.    
  111.   </p>
  112.     <p><b>4. How much hours approximately do You spend on social media?</b>
  113.     </p>
  114.      <select name="hours">
  115.      
  116.       <option value="less than 2 hours">less than 2 hours a day</option>
  117.       <option value="2-4 hours">2-4 hours a day</option>
  118.       <option value="4-8 hours">4-8 hours a day</option>
  119.       <option value="8-12 hours">8-12 hours a day</option>
  120.       <option value="more than 12 hours">more than 12 hours a day</option>
  121.      </select> 
  122.      
  123.    
  124.   <p>&nbsp;</p>
  125.     
  126.       
  127.       <p>
  128.       <!-- 5 vopros -->
  129.       
  130.       <b>5. Do You use social media often?</b></p>
  131.       <p>
  132.      
  133.       <input type="radio" name="often" value="Yes" />
  134.       Yes
  135.     <input type="radio" name="often" value="No" /> No
  136.      
  137.       
  138.       <!-- 6 vopros -->
  139.       </p>
  140.       <p><b>6. Social Media website to which You usually upload</b></p>
  141.   <p>
  142.      <input type="radio" name="upload" value="Youtube" /> Youtube<br></br>
  143.     <input type="radio" name="upload" value="Flickr" /> Flickr<br></br>
  144.     <input type="radio" name="upload" value="Photobucket" /> Photobucket<br></br>
  145.     <input type="radio" name="upload" value="Slideshare" /> Slideshare<br></br>
  146.     <input type="radio" name="upload" value="Other" /> Other 
  147.   </p>
  148.    
  149.      <!-- 7 vopros -->
  150.      
  151.     <b>7. Where do You chat with Your friends</b>
  152.   
  153.   <select name="chatting">
  154.     
  155.    <option value="Msn">Msn</option>
  156.     <option value="Skype">Skype</option>
  157.     <option value="Yahoo!">Yahoo!</option>
  158.     <option value="Other">Other</option>
  159.   </select>
  160.   <p>&nbsp;</p>
  161.  
  162.   
  163.    
  164.    <!-- 8 vopros -->
  165.  <b>8. You use social media for</b>  
  166.   
  167.    
  168.    <select name="using">
  169.     
  170.     <option value="Personal reasons">Personal reasons</option>
  171.     <option value="Professional reasons">Professional reasons</option>
  172.     <option value="Don't use it">Don't use it</option> 
  173.    </select>
  174.    
  175.   <p>&nbsp;</p>
  176.  
  177.  
  178.   <p>
  179.    <!-- 9 vopros -->
  180.    
  181.    <b>9. You prefer to obtain the information You need at</b> 
  182.    
  183.    
  184.    <select name="information">
  185.     
  186.     <option value="Yahoo!">Yahoo!</option>
  187.     <option value="Google">Google</option>
  188.     <option value="Wikipedia">Wikipedia</option>
  189.     <option value="Ask">Ask</option>
  190.     <option value="Other">Other</option> 
  191.    </select>
  192.   </p>
  193.   
  194.    
  195.    
  196.    <!-- 10 vopros -->
  197.    
  198.    <b>10. What do You prefer to do being online</b>?
  199.   
  200.    
  201.    <select id="drop" name="online">
  202.     <option value="Read blogs">Read blogs</option>
  203.     <option value="Chat with friends">Chat with friends</option>
  204.     <option value="Watch videos">Watch videos</option>
  205.     <option value="Read news">Read news</option>
  206.     <option value="Other">Other</option> 
  207.    </select>
  208.   
  209.   
  210.   <!-- konec voprosov -->
  211.   
  212.   <!-- button-submit -->
  213.   <p align="center">
  214.  <input type="submit" value="Submit" />
  215.  </p>
  216.  </form>
  217. <!-- end #container -->
  218. </div>
  219. </body>
  220. </html>


Javascript validation :
Code: [ Select ]
//Javascript Document

function checkform ( form )
{

 if (form.occupation.value == "") {
  alert( "Please enter your occupation." );
  form.occupation.focus();
  return false ;
 }
 return true ;
}


function checkform(f) {
 for (var i=0; i<f.elements("gender").length;
  i++) {
  var radio = f.elements("gender")[i];
  if (radio.checked) {
   return true;
  }
 }
 // no checked radio button found
 window.alert("Choose your gender!");
 f.elements("gender")[0].focus();
 return false;
}

function checkform(f) {
 for (var i=0; i<f.elements("job").length;
  i++) {
  var radio = f.elements("job")[i];
  if (radio.checked) {
   return true;
  }
 }
 // no checked radio button found
 window.alert("Choose if you have a job!");
 f.elements("job")[0].focus();
 return false;
}

function checkform(f) {
 for (var i=0; i<f.elements("bla").length;
  i++) {
  var radio = f.elements("bla")[i];
  if (radio.checked) {
   return true;
  }
 }
 // no checked radio button found
 window.alert("Answer question number 1");
 f.elements("bla")[0].focus();
 return false;
}

function checkform(f) {
 for (var i=0; i<f.elements("use").length;
  i++) {
  var radio = f.elements("use")[i];
  if (radio.checked) {
   return true;
  }
 }
 // no checked radio button found
 window.alert("Answer question number 3!");
 f.elements("use")[0].focus();
 return false;
}

function checkform(f) {
 for (var i=0; i<f.elements("often").length;
  i++) {
  var radio = f.elements("often")[i];
  if (radio.checked) {
   return true;
  }
 }
 // no checked radio button found
 window.alert("Answer question number 5!");
 f.elements("often")[0].focus();
 return false;
}

function checkform(f) {
 for (var i=0; i<f.elements("upload").length;
  i++) {
  var radio = f.elements("upload")[i];
  if (radio.checked) {
   return true;
  }
 }
 // no checked radio button found
 window.alert("Answer question number 6!");
 f.elements("upload")[0].focus();
 return false;
}
  1. //Javascript Document
  2. function checkform ( form )
  3. {
  4.  if (form.occupation.value == "") {
  5.   alert( "Please enter your occupation." );
  6.   form.occupation.focus();
  7.   return false ;
  8.  }
  9.  return true ;
  10. }
  11. function checkform(f) {
  12.  for (var i=0; i<f.elements("gender").length;
  13.   i++) {
  14.   var radio = f.elements("gender")[i];
  15.   if (radio.checked) {
  16.    return true;
  17.   }
  18.  }
  19.  // no checked radio button found
  20.  window.alert("Choose your gender!");
  21.  f.elements("gender")[0].focus();
  22.  return false;
  23. }
  24. function checkform(f) {
  25.  for (var i=0; i<f.elements("job").length;
  26.   i++) {
  27.   var radio = f.elements("job")[i];
  28.   if (radio.checked) {
  29.    return true;
  30.   }
  31.  }
  32.  // no checked radio button found
  33.  window.alert("Choose if you have a job!");
  34.  f.elements("job")[0].focus();
  35.  return false;
  36. }
  37. function checkform(f) {
  38.  for (var i=0; i<f.elements("bla").length;
  39.   i++) {
  40.   var radio = f.elements("bla")[i];
  41.   if (radio.checked) {
  42.    return true;
  43.   }
  44.  }
  45.  // no checked radio button found
  46.  window.alert("Answer question number 1");
  47.  f.elements("bla")[0].focus();
  48.  return false;
  49. }
  50. function checkform(f) {
  51.  for (var i=0; i<f.elements("use").length;
  52.   i++) {
  53.   var radio = f.elements("use")[i];
  54.   if (radio.checked) {
  55.    return true;
  56.   }
  57.  }
  58.  // no checked radio button found
  59.  window.alert("Answer question number 3!");
  60.  f.elements("use")[0].focus();
  61.  return false;
  62. }
  63. function checkform(f) {
  64.  for (var i=0; i<f.elements("often").length;
  65.   i++) {
  66.   var radio = f.elements("often")[i];
  67.   if (radio.checked) {
  68.    return true;
  69.   }
  70.  }
  71.  // no checked radio button found
  72.  window.alert("Answer question number 5!");
  73.  f.elements("often")[0].focus();
  74.  return false;
  75. }
  76. function checkform(f) {
  77.  for (var i=0; i<f.elements("upload").length;
  78.   i++) {
  79.   var radio = f.elements("upload")[i];
  80.   if (radio.checked) {
  81.    return true;
  82.   }
  83.  }
  84.  // no checked radio button found
  85.  window.alert("Answer question number 6!");
  86.  f.elements("upload")[0].focus();
  87.  return false;
  88. }


Where is my mistake?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Nightslyr
  • Proficient
  • Proficient
  • Nightslyr
  • Posts: 283

Post 3+ Months Ago

Your mistake is that you keep redefining your checkForm function over and over again. The end result is that only your last definition of the function, which checks the last input, actually exists.

You only need one checkForm function. Combine what you have.
  • bido
  • Newbie
  • Newbie
  • bido
  • Posts: 6

Post 3+ Months Ago

Thanks, but how to combine it so that validation worked properly?
  • Nightslyr
  • Proficient
  • Proficient
  • Nightslyr
  • Posts: 283

Post 3+ Months Ago

JAVASCRIPT Code: [ Select ]
//Javascript Document
function checkform(form) {
   var errors = new Array();
 
   if (form.occupation.value == "") {
      errors.push("Please enter your occupation.");
   }
 
   var gender = form.elements["gender"];
   var genderCount = 0;
 
   for (var i = 0; i < gender.length; i++) {
      var radio = gender[i];
 
      if (radio.checked) {
         ++genderCount;
      }
   }
     
   if (genderCount === 0) {
      // no checked radio button found
      errors.push("Choose your gender!");
   }
 
   var job = form.elements["job"];
   var jobCount = 0;
 
   for (var i = 0; i < job.length; i++) {
      var radio = job[i];
 
      if (radio.checked) {
         ++jobCount;
      }
   }
 
   if (jobCount === 0) {
      // no checked radio button found
      errors.push("Choose if you have a job!");
   }
 
   var bla = form.elements["bla"];
   var blaCount = 0;
 
   for (var i = 0; i < bla.length; i++) {
      var radio = bla[i];
 
      if (radio.checked) {
         ++blaCount;
      }
   }
 
   if (blaCount === 0) {
      // no checked radio button found
      errors.push("Answer question number 1");
   }
 
   var use = form.elements["use"];
   var useCount = 0;
 
   for (var i = 0; i < use.length; i++) {
      var radio = use[i];
 
      if (radio.checked) {
         ++useCount;
      }
   }
 
   if (useCount === 0) {
      // no checked radio button found
      errors.push("Answer question number 3!");
   }
 
   var often = form.elements["often"];
   var oftenCount = 0;
 
   for (var i = 0; i < often.length; i++) {
      var radio = often[i];
 
      if (radio.checked) {
         ++oftenCount;
      }
   }
 
   if (oftenCount === 0) {
      // no checked radio button found
      errors.push("Answer question number 5!");
   }
 
   var upload = form.elements["upload"];
   var uploadCount = 0;
 
   for (var i = 0; i < upload.length; i++) {
      var radio = upload[i];
 
      if (radio.checked) {
         ++uploadCount;
      }
   }
 
   if (uploadCount === 0) {
      // no checked radio button found
      errors.push("Answer question number 6!");
   }
 
   if (errors.count > 0) {
      // display validation errors
      return false;
   }
   else {
      return true;
   }
  1. //Javascript Document
  2. function checkform(form) {
  3.    var errors = new Array();
  4.  
  5.    if (form.occupation.value == "") {
  6.       errors.push("Please enter your occupation.");
  7.    }
  8.  
  9.    var gender = form.elements["gender"];
  10.    var genderCount = 0;
  11.  
  12.    for (var i = 0; i < gender.length; i++) {
  13.       var radio = gender[i];
  14.  
  15.       if (radio.checked) {
  16.          ++genderCount;
  17.       }
  18.    }
  19.      
  20.    if (genderCount === 0) {
  21.       // no checked radio button found
  22.       errors.push("Choose your gender!");
  23.    }
  24.  
  25.    var job = form.elements["job"];
  26.    var jobCount = 0;
  27.  
  28.    for (var i = 0; i < job.length; i++) {
  29.       var radio = job[i];
  30.  
  31.       if (radio.checked) {
  32.          ++jobCount;
  33.       }
  34.    }
  35.  
  36.    if (jobCount === 0) {
  37.       // no checked radio button found
  38.       errors.push("Choose if you have a job!");
  39.    }
  40.  
  41.    var bla = form.elements["bla"];
  42.    var blaCount = 0;
  43.  
  44.    for (var i = 0; i < bla.length; i++) {
  45.       var radio = bla[i];
  46.  
  47.       if (radio.checked) {
  48.          ++blaCount;
  49.       }
  50.    }
  51.  
  52.    if (blaCount === 0) {
  53.       // no checked radio button found
  54.       errors.push("Answer question number 1");
  55.    }
  56.  
  57.    var use = form.elements["use"];
  58.    var useCount = 0;
  59.  
  60.    for (var i = 0; i < use.length; i++) {
  61.       var radio = use[i];
  62.  
  63.       if (radio.checked) {
  64.          ++useCount;
  65.       }
  66.    }
  67.  
  68.    if (useCount === 0) {
  69.       // no checked radio button found
  70.       errors.push("Answer question number 3!");
  71.    }
  72.  
  73.    var often = form.elements["often"];
  74.    var oftenCount = 0;
  75.  
  76.    for (var i = 0; i < often.length; i++) {
  77.       var radio = often[i];
  78.  
  79.       if (radio.checked) {
  80.          ++oftenCount;
  81.       }
  82.    }
  83.  
  84.    if (oftenCount === 0) {
  85.       // no checked radio button found
  86.       errors.push("Answer question number 5!");
  87.    }
  88.  
  89.    var upload = form.elements["upload"];
  90.    var uploadCount = 0;
  91.  
  92.    for (var i = 0; i < upload.length; i++) {
  93.       var radio = upload[i];
  94.  
  95.       if (radio.checked) {
  96.          ++uploadCount;
  97.       }
  98.    }
  99.  
  100.    if (uploadCount === 0) {
  101.       // no checked radio button found
  102.       errors.push("Answer question number 6!");
  103.    }
  104.  
  105.    if (errors.count > 0) {
  106.       // display validation errors
  107.       return false;
  108.    }
  109.    else {
  110.       return true;
  111.    }


This validation script will check all of the inputs upon form submission. What it will not do is focus on individual form elements if they fail validation. To do that, you'd need to have an individual validator on each element which would fire on the onblur event.

Also note that this isn't tested. You may have to do some work to get it to fit your needs. Regardless, you'll have to figure out how/where to display the validation errors as I left that part up to you.
  • bido
  • Newbie
  • Newbie
  • bido
  • Posts: 6

Post 3+ Months Ago

Ok, thank you for help!!

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 110 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.