0
votes

I have 2 radio buttons on an ASP.NET WebForm page. I have a modal popup that is to be shown only when going from one of the radio buttons to the other, but not the other way. In other words, here are my choices:

  1. if radio button 1 is clicked then the modal popup is shown.
  2. If radio button 1 is currently selected and radio button 2 is clicked then the modal popup should NOT be shown. I have a javascript function that toggles the show and hide but I briefly see the popup when #2 logic is performed. Here is the js function:
        $(function () {
            $('#<%=RadioButtonListServiceLevel.ClientID%>').click(function () {
                var CustomerCountry = $('#<%=HiddenFieldCustomerCountry.ClientID%>').val();
                var ServiceLevelSelected = $("#<%=RadioButtonListServiceLevel.ClientID%> input:checked").val();
                if ((CustomerCountry != "US" && CustomerCountry != "CA") && ServiceLevelSelected == "24") {
                    $('#InternationalServiceLevelModal').modal('show');
                } else {
                    $('#InternationalServiceLevelModal').modal('hide');
                }
            });
        });

Any idea why the popup modal dialog would briefly show when the action described in #2 is performed?

Thanks

1
Btw, if you set <pages clientIDMode="Static"... in web.config you don't have to use .ClientID.wazz

1 Answers

0
votes

I was just playing around a bit using an 'alert' and when I used the 'click' event, like you have, the alert fired twice: as soon as i clicked - before the button visibly changed value, then again after the button visibly changed value.

I changed 'click' to 'change' and the alert only fired once. Could be the fix?

// changed 'click' to 'change'
$('#<%=RadioButtonListServiceLevel.ClientID%>').change(function () {