Web Analytics Made Easy -
StatCounter My validation script is not validating all controls. Any ideas why? - CodingForum

Announcement

Collapse
No announcement yet.

My validation script is not validating all controls. Any ideas why?

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

  • My validation script is not validating all controls. Any ideas why?

    Greetings again gurus.

    I have the following JS script:

    Code:
      <script type="text/javascript" lang="javascript">
    
             function ValidateAll() {
                 var errorCounter = 0;
                 var errorMessage = "";
    
                 //Smoke or not
                  if ((!($('#dontsmoke').prop('checked'))) && (!($('#smokeornot').prop('checked'))) && (!($('#smokeo').prop('checked')))) {
                    errorMessage += " Please choose an option that applies to you.<br/>";
                    errorCounter++;
                }
                 //End
    
                 //Your Choice
                 if (!($('#acknowledgement').prop('checked')))
                 {
                     errorMessage += " You must check the box to certify information provided is correct in order to continue.<br/>";
                     errorCounter++;
                 }
                 //End
    
                 //Name
                 if ($("#lblName").val() == '') {
                     errorMessage += " Enter your Name<br/>";
                     errorCounter++;
                 }
                 //End
    
                 //Signature
                 if ($("#signature").val() == '') {
                     errorMessage += " Your signature is required<br/>";
                     errorCounter++;
                 }
                 //End
    
                 //Phone
                 if ($("#lblPhone").val() == '') {
                     errorMessage += " Enter your Phone Number<br/>";
                     errorCounter++;
                 }
                 //End
    
                 //Phone
                 if ($("#lblEmail").val() == '') {
                     errorMessage += " Enter your Phone Number<br/>";
                     errorCounter++;
                 }
                 //End
    
                 $("#errorDiv").html(errorMessage);
                 if (errorCounter == 0) {
                   //  alert('Your response successfully submitted.')
                     return true;
                 }
                 else
                 {
                     return false;
                 }
             }
         </script>
         <script type="text/javascript">
             $(document).ready(function () {
                 $("#submitButton").click(function (e) {
                     var result = ValidateAll();
    
                     return result;
                 });
             });
    	</script>
    Then the following html:

    Code:
     <input type="radio" name="smokeornot" id="dontsmoke" value="do not"></td>
     <td>I attest that I <span style="font-weight:bold;">do not</span> need product(s).</td></tr>
     <tr>
      <td>&nbsp;</td></tr>
     <tr>
      <td>
     <input type="radio" name="smokeornot" id="smokeornot" value="Need products"></td>
     <td>I acknowledge that <span style="font-weight:bold;">I do</span> need producrs. </td></tr>
     <tr>
      <td>&nbsp;</td></tr>
     <tr>
      <td>
       <input type="radio" name="smokeornot" id="smokeo" value="I will consider your offer"></td>
       <td>I acknowledge that  <span style="font-weight:bold;">I will</span> consider your offer</td></tr></table></div>
     <br>
     <input type="checkbox" name="acknowledgement" id="acknowledgement" value="1" />
     <label for="acknowledgement">I certify that all information provided by me is complete and accurate.</label><br><br>
     <table>
       <tr>
        <td>Employee Name:</td><td><input name="lblName" id="lblName" ReadOnly  style="background:beige;" type="text"  width="300" value="<?=$fname;?>"></td></tr>
      <tr>
       <td>Signature:</td><td><input type="text" name="signature" value=""> </td></tr>
      <tr>
       <td>Date:</td><td><input type="text" name="lblDate" ReadOnly style="background:beige;" value="<?= date("m/d/Y h:i:s a", time());?>"> </td></tr>
      <tr>
       <td>Phone Number:</td><td><input type="text" name="lblPhone"  onkeydown="javascript:backspacerDOWN(this,event);" onkeyup="javascript:backspacerUP(this,event);" value=""> </td></tr>
         <tr>
       <td>Email:</td><td><input type="text" name="lblPEmail" value=""> </td></tr></table>
       <hr>
       <input type="submit" class="button" name="submit" id="submitButton" value="Submit response >>">
    When I run the code, only radio buttons and checkbox are being validated.

    The rest of the controls are ignored.

    Any ideas what I am doing wrong?

    Thanks for your help in advance

  • #2
    sorry - found the problem.

    Please ignore.

    Thanks

    Comment


    • #3
      You don't need JavaScript for those validations - that can all be done in the HTML.
      Stephen
      Learn Modern JavaScript - http://javascriptexample.net/
      Helping others to solve their computer problem at http://www.felgall.com/

      Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

      Comment


      • #4
        html5 that is but that's not what I am using currently.

        maybe I should switch to that

        Comment


        • #5
          All current browsers are using HTML 5.

          HTML 5 includes HTML 4 and even much of HTML 3.2 so all web pages are using HTML 5 anyway.

          Browsers don't check what version of HTML you are using so as to apply the correct styling rules which is one reason why HTML 5 no longer uses an SGML doctype to point to the rules.
          Stephen
          Learn Modern JavaScript - http://javascriptexample.net/
          Helping others to solve their computer problem at http://www.felgall.com/

          Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

          Comment

          Working...
          X