Click here to Skip to main content
15,885,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have to hide or show div by using radio button list and jquery ,

my html code is ...

XML
<div id="TransactionTypeDivForResidential" class="postline" runat="server">
    <p class="postText">Transaction Type Required :</p>
    <asp:RadioButtonList ID="RbtnTransactionTypeForResidential" ValidationGroup="View1"  runat="server" RepeatDirection="Horizontal" AutoPostBack="True" OnSelectedIndexChanged="RbtnTransactionTypeForResidential_SelectedIndexChanged">

    </asp:RadioButtonList>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" ValidationGroup="View1"  CssClass="validation" Display="Dynamic" ControlToValidate="RbtnTransactionTypeForResidential" runat="server" ErrorMessage="select transaction type"></asp:RequiredFieldValidator>
</div>



and

jquery script is ...

XML
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script  type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js">
        $(document).ready(function () {
            $('#RbtnPropertyType input').click(function () {
                var value = $('#RbtnPropertyType input:checked').val();
                if (value == 100010000000000008) {
                    $("#TransactionTypeDivForCommercial").show();
                    $("#TransactionTypeDivForResidential").hide();

                }
                if (value == 100010000000000007) {
                    $("#TransactionTypeDivForCommercial").hide();
                    $("#TransactionTypeDivForResidential").show();

                }


            });
        });
</script>
</asp:Content>




this jquery script is inside child page of master page as seen in script ,

but this is not working , though not calling the jquery function ...

whats wrong in this i googled the net , but not find anything .. any help will be appreciated , thanx in advanse dudes....
Posted
Comments
KaushalJB 12-May-14 7:35am    
Check your asp:RadioButtonList Id.
Its different from $('#RbtnPropertyType input').click(function (). And where are your asp:RadioButtonList values in design ?
GDdixit 12-May-14 7:39am    
actually its right , the upere line of source code is ...

<asp:RadioButtonList ID="RbtnPropertyType" ValidationGroup="View1" runat="server" RepeatDirection="Horizontal" AutoPostBack="false" >





i forget this to write ..
KaushalJB 12-May-14 7:45am    
Be specific in copying GD..
DotNet WeblineIndia 12-May-14 9:01am    
GD i suggest you to check the exact id of the controls in "firebug" of Mozilla or "Development tool" of Chrome. For example if the controls reside within the "ControlPlaceHolder" than the Control's id of each controls reside within also get change.

1 solution

See the working code here:
C#
<asp:radiobuttonlist id="RadioButtonList1" runat="server" ClientIDMode="static">
        <asp:listitem text="Residential" value="Residential"></asp:listitem>
        <asp:listitem text="Commercial" value="Commercial"></asp:listitem>
</asp:radiobuttonlist>
<div id="res"  runat="server">Residential</div>
<div id="com"  runat="server">Commerecial</div>

And the JQuery:
XML
<script type="text/javascript">
       $(document).ready(function () {
           $("#RadioButtonList1").change(function () {              
               var sel = $('#RadioButtonList1 input:checked').val()
               if (sel == "Residential") {
                   $("#com").hide();
                   $("#res").show();
               }
               if (sel == "Commercial") {
                   $("#com").show();
                   $("#res").hide();
               }
           });
           return false;

       });
   </script>

Regards..
 
Share this answer
 
v3
Comments
KaushalJB 12-May-14 7:43am    
Bravo.. 5
GDdixit 12-May-14 8:01am    
i have used ur code jquery code is called on selecting radio button item , anf also finding 'if' condition true in code but on page div is not hide or not showing , ... ?
Thanks7872 12-May-14 8:30am    
I tested this code and its working fine. Try one thing,keep ids and everything as it is,put your design inside this and give it a try.
Thanks7872 12-May-14 8:53am    
Dont you notice ClientIDMode="static" in the solution? Further,you have made comment to my solution,so GD will not get notified. Better post comment right below the question or use reply button at GD's comment.

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