asp.net, jquery, validation, radiobutton

Webboy2008
Webboy2008 used Ask the Experts™
on
I have the following codes working fine but want to do one more validation

If the rdoadministrator is selected yes (value = 1), I would like to make sure the user enter all of the information (like city, state, zip, address, and etc.).
How can I modify the current jquery script?

Thanks

<script type="text/javascript">

    // a custom onComplete handler to prevent form submits for the demo
    function myOnComplete() {
        //alert("The form validates! (normally, it would submit the form here).");
        //return false;
    }
    $(document).ready(function() {
    $("#frmquoteadditional").RSV({
            onCompleteHandler: myOnComplete,
            displayType: "display-html",
            errorFieldClass: "errorFieldDemo2",
            rules: [
            "required,rdoadministrator, Is Plan serviced by an Independent Administrator?",
                  "required,rdoadministrator,Please enter Administrator Name.",
                  "required,rdocpa,Is Plan audited annually by the CPA?",
                  "required,txttrustee1Ssn1,Please enter primary Trustee SSN.",
                  "required,txttrustee1Ssn2,Please enter primary Trustee SSN.",
                  "required,txttrustee1Ssn3,Please enter primary Trustee SSN.",
                  "required,txttrusteeaddr1,Please enter primary Trustee Address.",
                  "required,txttrusteecity1,Please enter primary Trustee City.",
                  "required,txttrusteestate1,Please enter primary Trustee State.",
                  "required,txttrusteezip1,Please enter primary Trustee Zip code."
            ]
        });
       
    });      </script>
<%
 p=p & "<table cellpadding=""0"" cellspacing=""0""  width=""100%"">"
    p=p & "<tr><td width=""330""><b>Is the Plan serviced by an Independent Administrator?</b></td>"
    p=p & "<td>&nbsp;"
    p=p & "<input type=""radio"" name=""rdoadministrator"" value=""1""  />Yes"
    p=p & "&nbsp;"
    p=p & "<input type=""radio"" name=""rdoadministrator"" value=""0"" />No"
    p=p & "</td></tr></table>"
 p=p & "<table>"
          p=p & "<Tr valign=""top""><td width=""330""><STRONG>Name of Administrator:</STRONG></td>"
          P=P & "<td><input size=""40"" class=""textboxdata"" name=""txtadminname"" value=""" & Request.Form("txtadminname") & """>"
          P=P & "</td></tr>"
          p=p & "<Tr valign=""top""><Td width=""330""><STRONG>Address:</STRONG></td><Td><input size=""40"" class=""textboxdata"" type=""text"" name=""txtaddress1"" value=""" & Request.Form("txtaddress1") & """></td></tr>"
          p=p & "<tr valign=""top""><Td width=""330""><STRONG>City/State/Zip:</STRONG></td>"
          p=p & "<td>"
          p=p & "<input size=""19"" class=""textboxdata"" type=""text"" name=""txtcity1"" value=""" & Request.Form("txtcity1")   & """>&nbsp;"
          p=p & "<input size=""2""  class=""textboxdata"" maxlength=""2"" type=""text"" name=""txtstate1"" value=" & Request.Form("txtstate1") & ">&nbsp;"
          p=p & "<input onkeyup=""this.value=this.value.replace(/\D/gi,'')"" size=""5""  class=""textboxdata"" maxlength=""5"" type=""text"" name=""txtzip1""   value=" & Request.Form("txtzip1")   & ">"
          p=p & "</td>"
          p=p & "</tr>"          
          p=p & "</table>"      
%>
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Kiran SonawaneProject Lead
Top Expert 2011

Commented:
Try like this


function myOnComplete() {
        //alert("The form validates! (normally, it would submit the form here).");
        //return false;

       var returnFlag = true;
            if ($("input[name='rdoadministrator']:checked").val() == 1) {

                $(".textboxdata").each(function () {
                    if ($(this).val() == "") {
                        alert("Please enter name or address");
                        returnFlag = false;
                    }
                });
            }

          return returnFlag ;

   
    }
Jon NormanInformation Systems Manager
Top Expert 2012

Commented:
Try something like:


<script type="text/javascript">

    // a custom onComplete handler to prevent form submits for the demo
    function myOnComplete() {
        //alert("The form validates! (normally, it would submit the form here).");
        //return false;
    }
  function rdoadministratorChecker(){
    if ($("input[name='rdoadministrator']:checked").val() == 1) {
      if ($("input[name='txtadminname']).val()==""){
          alert("Please enter name");
          return false;
      }
      if ($("input[name='txtaddress1']).val()==""){
          alert("Please enter address");
          return false;
      }
      if ($("input[name='txtcity1']).val()==""){
          alert("Please enter city");
          return false;
      }
      if ($("input[name='txtzip1']).val()==""){
          alert("Please enter zip");
          return false;
      }
    }
    return true;
  }
    $(document).ready(function() {
    $("#frmquoteadditional").RSV({
            onCompleteHandler: myOnComplete,
            displayType: "display-html",
            errorFieldClass: "errorFieldDemo2",
            rules: [
                  "function,rdoadministratorChecker",
                  "required,rdocpa,Is Plan audited annually by the CPA?",
                  "required,txttrustee1Ssn1,Please enter primary Trustee SSN.",
                  "required,txttrustee1Ssn2,Please enter primary Trustee SSN.",
                  "required,txttrustee1Ssn3,Please enter primary Trustee SSN.",
                  "required,txttrusteeaddr1,Please enter primary Trustee Address.",
                  "required,txttrusteecity1,Please enter primary Trustee City.",
                  "required,txttrusteestate1,Please enter primary Trustee State.",
                  "required,txttrusteezip1,Please enter primary Trustee Zip code."
            ]
        });
       
    });      </script>
Information Systems Manager
Top Expert 2012
Commented:
hang on, this is probably better:


<script type="text/javascript">

    // a custom onComplete handler to prevent form submits for the demo
    function myOnComplete() {
        //alert("The form validates! (normally, it would submit the form here).");
        //return false;
    }
  function rdoadministratorChecker(){
    if ($("input[name='rdoadministrator']:checked").val() == 1) {
      var failures = new Array();
      var failed = false;
      if ($("input[name='txtadminname']).val()==""){
          failed = true;
          failures.push([$("input[name='txtadminname']),"Please enter name"]);
      }
      if ($("input[name='txtaddress1']).val()==""){
          failed = true;
          failures.push([$("input[name='txtaddress1']),"Please enter address"]);
      }
      if ($("input[name='txtcity1']).val()==""){
          failed = true;
          failures.push([$("input[name='txtcity1']),"Please enter city"]);
      }
      if ($("input[name='txtzip1']).val()==""){
          failed = true;
          failures.push([$("input[name='txtcity1']),"Please enter zip"]);
      }
      if (failed){
        return failures;
      }
    }
    return true;
  }
    $(document).ready(function() {
    $("#frmquoteadditional").RSV({
            onCompleteHandler: myOnComplete,
            displayType: "display-html",
            errorFieldClass: "errorFieldDemo2",
            rules: [
                  "function,rdoadministratorChecker",
                  "required,rdocpa,Is Plan audited annually by the CPA?",
                  "required,txttrustee1Ssn1,Please enter primary Trustee SSN.",
                  "required,txttrustee1Ssn2,Please enter primary Trustee SSN.",
                  "required,txttrustee1Ssn3,Please enter primary Trustee SSN.",
                  "required,txttrusteeaddr1,Please enter primary Trustee Address.",
                  "required,txttrusteecity1,Please enter primary Trustee City.",
                  "required,txttrusteestate1,Please enter primary Trustee State.",
                  "required,txttrusteezip1,Please enter primary Trustee Zip code."
            ]
        });
       
    });      </script>

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial