Avatar of Webboy2008
Webboy2008
 asked on

asp.net, jquery, validation, radiobutton

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>"      
%>
ASP.NETjQueryAJAX

Avatar of undefined
Last Comment
Jon Norman

8/22/2022 - Mon
Kiran Sonawane

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 Norman

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>
ASKER CERTIFIED SOLUTION
Jon Norman

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck