Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello All,


I am working on mvc application where i have two radio button. On radio button selection change i hide and show some controls.At the normal stage controls are show and hide on radio button change but when i post method is called and bind database value to radio button controls should be show and hide based on value which is bind but event is not fired.below are the code for reference.

I put debugger on the javascript and i get that $("input:radio[name='ApplicantType']").change(function () { this is not event to fired.debugger lost the focus on this line.

HTML
@Html.RadioButtonFor(m => m.ApplicantType, "INDV", new { @checked = "checked" })<span>Individual</span>
                            @Html.RadioButtonFor(m => m.ApplicantType, "ORG")<span>Organization</span>


<script type="text/javascript">
        $(document).ready(function () {
            $("#dvRepresented").hide();
            $("#dvPromoter").hide();
            $("#CustName").prop("disabled", true);
            $("#ApplicantName1").text("Applicant Name");
            $("input:radio[name='ApplicantType']").change(function () {
                var Selectedvalue = $(this).val();
                if (Selectedvalue == "INDV") {
                    $("#Entity").val("1");
                    $("#Entity").prop("disabled", true);
                    $("#CustName").prop("disabled", true);
                    $("#ApplicantName").text("Applicant Name");
                    $("#lblDOB").text("DOB");
                    $("#lblDOBProof").text("DOB/Age Proof");
                    $("#trAge").show();
                    $("#dvRepresented").hide();
                    $("#divPromoterDetails").hide();
                    $("#FullName").show();
                    $("#Gender").show();

                }
                else {
                    $("#Entity").prop("disabled", false);
                    $("#Entity").val("0");
                    $("#ApplicantName").text("Company Name");
                    $("#CustName").prop("disabled", false);
                    $("#lblDOB").text("DOI");
                    $("#lblDOBProof").text("DOI Proof");
                    $("#trAge").hide();
                    $("#dvRepresented").show();
                    $("#divPromoterDetails").show();

                    $("#FullName").hide();
                    $("#Gender").hide();
                }
            });
        });
    </script>


What I have tried:

I use (document).ready(function () but its not working after post.
Posted
Updated 4-Aug-16 0:41am
v2
Comments
Karthik_Mahalingam 4-Aug-16 2:19am    
try adding this at the bottom of the page
(document).ready(function ()

Use .trigger function on change function like this.
C#
$("button").click(function(){
    $("input").trigger("select");
});
 
Share this answer
 
$(document).ready(function() {
$('input[type=radio][name=ApplicantType]').change(function() {
if (this.value == "INDV") {
alert("Your Code");
}
else if (this.value == "ORG") {
alert("Your Code");
}
});
});
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900