Link to home
Start Free TrialLog in
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>"      
%>
Avatar of Kiran Sonawane
Kiran Sonawane
Flag of India image

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 ;

   
    }
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
Avatar of Jon Norman
Jon Norman
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial