By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,471 Members | 711 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,471 IT Pros & Developers. It's quick & easy.

chechkbox list validation

P: 19
Hi all


i have tried to validated the my textboxes and checkbox lists also,

i've write this following script



Expand|Select|Wrap|Line Numbers
  1. function validateResume()
  2. {
  3.     var FirstName = document.getElementById("txtFirstName");
  4.     var LastName = document.getElementById("txtLastName");
  5.     var Address1 = document.getElementById("txtAddress1");
  6.     var Address2 = document.getElementById("txtAddress2");
  7.     var City = document.getElementById("txtcity");
  8.     var State = document.getElementById("txtstate");
  9.     var Zip = document.getElementById("txtzip");
  10.     var DOB = document.getElementById("txtdob");
  11.     var Phone1 = document.getElementById("txtphn1");
  12.     var Phone2 = document.getElementById("txtphn2");
  13.     var Email = document.getElementById("txtemail");
  14.     var Skillset = document.getElementById("Chkskil");
  15.     var Qualification = document.getElementById("chkqualification");
  16.     var flag = 0;
  17.     if (FirstName.value == "") {
  18.         flag = 1;
  19.         document.getElementById("lblsave").innerHTML = "Please enter FirstName";
  20.         FirstName.focus();
  21.     }
  22.     else if (LastName.value == "") {
  23.         flag = 1;
  24.         document.getElementById("lblsave").innerHTML = "Please enter LastName";
  25.         LastName.focus();
  26.     }
  27.     else if (Address1.value == "") {
  28.         flag = 1;
  29.         document.getElementById("lblsave").innerHTML = "Please enter Address1";
  30.         Address1.focus();
  31.     }
  32.     else if (Address2.value == "") {
  33.         flag = 1;
  34.         document.getElementById("lblsave").innerHTML = "Please enter Address2";
  35.         Address2.focus();
  36.     }
  37.     else if (City.value == "") {
  38.         flag = 1;
  39.         document.getElementById("lblsave").innerHTML = "Please enter City";
  40.         City.focus();
  41.     }
  42.     else if (State.value == "") {
  43.         flag = 1;
  44.         document.getElementById("lblsave").innerHTML = "Please enter State";
  45.         State.focus();
  46.     }
  47.     else if (Zip.value == "") {
  48.         flag = 1;
  49.         document.getElementById("lblsave").innerHTML = "Please enter Zip";
  50.         Zip.focus();
  51.     }
  52.     else if (Zip.value.length != 6) {
  53.         flag = 1;
  54.         document.getElementById("lblsave").innerHTML = "Please Enter valid Zip ";
  55.         Zip.focus();
  56.     }
  57.     else if (DOB.value == "") {
  58.         flag = 1;
  59.         document.getElementById("lblsave").innerHTML = "Please enter DOB";
  60.         DOB.focus();
  61.     }
  62.     else if (Phone1.value == "") {
  63.         flag = 1;
  64.         document.getElementById("lblsave").innerHTML = "Please enter Phone1";
  65.         Phone1.focus();
  66.     }
  67.     else if (Phone1.value.length != 10) {
  68.         flag = 1;
  69.         document.getElementById("lblsave").innerHTML = "Please Enter Valid Phone1";
  70.             Phone1.focus();
  71.     }
  72.     else if (Phone2.value.length == "") {
  73.         flag = 1;
  74.         document.getElementById("lblsave").innerHTML = "Please Enter enter Phone2";
  75.         Phone2.focus();
  76.     }
  77.     else if (Phone2.value.length !=10) {
  78.         flag = 1;
  79.         document.getElementById("lblsave").innerHTML = "Please Enter Valid Phone2";
  80.             Phone2.focus();
  81.     }
  82.     else if (Email.value == "") {
  83.         flag = 1;
  84.         document.getElementById("lblsave").innerHTML = "Please enter email";
  85.         Email.focus();
  86.     }
  87.     else if (checkcontact(Email.value) == false) {
  88.         flag = 1;
  89.         document.getElementById("lblsave").innerHTML = "Please enter valid e-mail";
  90.         Email.focus();
  91.     }
  92.     else if (document.getElementById('FileUpload1').value.trim() == "") {
  93.        flag = 1;
  94.        document.getElementById('lblsave').innerHTML = "Browse a Document";
  95.        if (hdnSecretValue.value > 0)
  96.         {
  97.            document.getElementById('lblsave').style.display = 'none';
  98.           return true;
  99.         }
  100.     }
  101.     else if (Skillset=='0') {
  102.         flag = 1;
  103.    var test = Skillset.getElementsByTagName("input").length;
  104.     var count = 0;
  105.     for (var i = 0; i < test; i++) {
  106.         if (test[i].checked) {
  107.             count = 1;
  108.         }
  109.     }
  110.     if (count == 0) {
  111.         document.getElementById('lblsave').innerText = "Select Users!";
  112.         return false;
  113.     }
  114. }
  115.     else if (Qualification == '0') {
  116.         flag = 1;
  117.         var test2 = Qualification.getElementsByTagName("input").length;
  118.         var count = 0;
  119.         for (var i = 0; i < test; i++) {
  120.             if (test2[i].checked) {
  121.                 count = 1;
  122.             }
  123.         }
  124.         if (count == 0) {
  125.             document.getElementById('lblsave').innerText = "Select Users!";
  126.             return false;
  127.         }
  128.     }
  129.     if (flag == 0) {
  130.         return true;
  131.     }
  132.     else {
  133.         $('#divErrormsg').fadeIn(2000);
  134.         return false;
  135.     }
  136. }
  137.  

All the text box fields are working fine, but the chechkbox list are does not work, i've tried in many ways, i don't know what i'm doing wrong.. can someone help me with this?..
Oct 7 '16 #1
Share this Question
Share on Google+
2 Replies


Dormilich
Expert Mod 5K+
P: 8,639
i don't know what i'm doing wrong
you treat integers as a list.
var test = Skillset.getElementsByTagName("input").length;
Oct 7 '16 #2

P: 19
It is a string..


Thanks
Oct 7 '16 #3

Post your reply

Sign in to post your reply or Sign up for a free account.