1

I have a radio button and a radio button list used for making chart in asp.net... These two buttons represent two different values and I cannot combine them... I want to un-check the radio button if any one of the buttons in the radio button list is clicked and vice versa...

$(document).ready(function() {
    $("[id*=rbtnZone]").click(function() {
        $('#<%=rbtnStore.ClientID %> input:radio').each(function() {
            $(this).prop('checked', false);
        });
    });

    $("[id*=rbtnStore]").change(function() {
        $('#rbtnZone').prop('checked', false);
    });

 });


$(function() {
        $("[id*=rbtnStore]").click(function() {
            var row = $(this).closest('tr');
            var branchId = $(row).find('[id*=hfBranchId]').val();
            var rbtlSales = $("#<%= rbtlSales.ClientID%>");
            var selectedValue = rbtlSales.find("input:checked").val();

            var rbtnStore = $("#<%=rbtnStore.ClientID %>");
            var selectedZone = rbtnStore.find("input:checked").val();

            document.getElementById('<%=rbtlSales.ClientID %>').checked = false;

            var dt = new Date();
            /*Getting Todays Date only*/
            var ddt = new Date(dt.getFullYear(), dt.getMonth(), dt.getDate(), dt.getDay());
            ddt = ddt.toDateString();

            /*Yesterday's Date*/
            var ytd = new Date(new Date() - 24 * 60 * 60 * 1000);
            ytd = ytd.toDateString();

            /*Current Month First Date*/
            var firstdate = new Date(dt.getFullYear(), dt.getMonth(), 1);
            firstdate = firstdate.toDateString();

            /*Previous Month First & Last Dates*/
            var prevfirstday = new Date(dt.getFullYear(), dt.getMonth() - 1, 1);
            prevfirstday = prevfirstday.toDateString();
            var prevlastday = new Date(dt.getFullYear(), dt.getMonth(), 0);
            prevlastday = prevlastday.toDateString();

            if (selectedValue == 'today') {
                var lblHead = 'Todays Sales of ' + selectedZone + ' @ ' + dt;
                document.getElementById('<%=lblStoreName.ClientID %>').innerHTML = lblHead;
            }
            else if (selectedValue == 'yesterday') {
                var lblHead = 'Sales Report of ' + selectedZone + ' on ' + ytd;
                document.getElementById('<%=lblStoreName.ClientID %>').innerHTML = lblHead;
            }
            else if (selectedValue == 'mtd') {
                var lblHead = 'Sales Report of ' + selectedZone + ' from ' + firstdate + ' to ' + ytd;
                document.getElementById('<%=lblStoreName.ClientID %>').innerHTML = lblHead;
            }
            else if (selectedValue == 'prevmonth') {
                var lblHead = 'Sales Report of ' + selectedZone + ' From ' + prevfirstday + ' to ' + prevlastday;
                document.getElementById('<%=lblStoreName.ClientID %>').innerHTML = lblHead;
            }
            else if (selectedValue == 'ytd') {
                var lblHead = 'Sales Report of ' + selectedZone + ' From 1 April 2015 to ' + ddt;
                document.getElementById('<%=lblStoreName.ClientID %>').innerHTML = lblHead;
            }


            $.ajax({
                url: '<%=ResolveUrl("~/Corporate/Sales.aspx/GetStoreData") %>',
                data: "{'rbtlSales':'" + selectedValue + "','rbtnStore':'" + selectedZone + "'}",
                dataType: "json",
                type: "POST",
                contentType: "application/json; charset=utf-8",
                success: function(data) {
                    var labels = [];
                    var datas = [];
                    $.each(data.d, function(i, item) {
                        var l = item.split('/')[0];
                        var d = item.split('/')[1];
                        var dd = d | 0;
                        labels.push(l);
                        datas.push(dd);
                    });
                    var barChartLocData =
            {
                labels: labels,
                datasets:
                [
                    {
                        fillColor: "lightgreen",
                        highlightFill: "lightgreen",
                        data: datas
                    }
                ]
            };
                    var ctx = document.getElementById("canvas").getContext("2d");
                    new Chart(ctx).HorizontalBar(barChartLocData, {
                        responsive: true,
                        scaleFontColor: "#000",
                        showTooltips: false,
                        onAnimationComplete: function() {
                            var ctx = this.chart.ctx;
                            ctx.font = this.scale.font;
                            ctx.fillStyle = this.scale.textColor
                            ctx.textAlign = "right";
                            ctx.textBaseline = "right";
                            this.datasets.forEach(function(dataset) {
                                dataset.bars.forEach(function(bar) {
                                    ctx.fillText(bar.value, bar.x, bar.y - 5);
                                });
                            });
                        }
                    });
                },
                error: function(response) {
                },
                failure: function(response) {
                }
            });
        });
    });
    
<asp:RadioButton ID="rbtnZone" runat="server" GroupName="rb" Text="Zone Wise" />
 
<asp:RadioButtonList ID="rbtnStore" runat="server" CellPadding="3" GroupName="rb" RepeatColumns="4" RepeatDirection="Horizontal">
</asp:RadioButtonList>

<!-- begin snippet: js hide: false -->

4
  • That is .Net code, but you tagged the question as JavaScript and HTML. Please add the generated HTML code and not the ASP code to your question. Commented Dec 16, 2015 at 11:57
  • What should i do to change the tags? Commented Dec 16, 2015 at 12:15
  • You can edit the question to edit the tags. But it seems that you are looking for a JavaScript solution, so it would be better to add the generated HTML code instead of adding the .net tag Commented Dec 16, 2015 at 12:16
  • I have added the html code... please look into it... Actually i have made half my job done... The list is getting unchecked on clicking on the radio button... But the button is not unchecked on clicking the list... Commented Dec 16, 2015 at 12:30

4 Answers 4

2

You can use the below code :

$(document).ready(function (){
if($('#rbtnZone').is(':checked')){
    $('#rbtnStore').attr('checked',false)
}
else if($('#rbtnStore').is(':checked')){
    $('#rbtnZone').attr('checked',false)
}

$('#rbtnZone').on('change',function (){
    if($(this).is(':checked')){
        $('#rbtnStore').attr('checked',false)
    }
});

$('#rbtnStore').on('change',function (){
    if($(this).is(':checked')){
        $('#rbtnZone').attr('checked',false)
    }
});
});
Sign up to request clarification or add additional context in comments.

Comments

1

Once you have pick the desired Radio through DOM, you just have to state:

Radio.setValue(true/false);

and it will be checked depending on what you want.

Comments

0

you can use this code

document.getElementById("rbtnZone").checked = true;    
document.getElementById("rbtnZone").checked = false;

1 Comment

No, i have already tried that... There are two javascript click functions in the same page for chart drawing... The charts works fine, but on clicking on the radio button list, the radio button is also checked...
0

I got a solution...

$(document).ready(function() {
    $("[id*=rbtnZone]").click(function() {
        $('#<%=rbtnStore.ClientID %> input:radio').each(function() {
            $(this).prop('checked', false);
        });
    });

    $("[id*=rbtnStore]").change(function() {
    $('#<%=rbtnZone.ClientID %>').prop('checked', false);
    });

});

Thanks for helping by the way...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.