This is a migrated thread and some comments may be shown as answers.

Problem with Combobox onChange event

5 Answers 124 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Narayanarao
Top achievements
Rank 1
Narayanarao asked on 27 Mar 2012, 01:13 PM

Hi Team,

    We have 2 combo boxes with parent child relation(ex : Country and State). Whenever there is a change in country corresponding states has to be loaded on OnChange() client event.

    When we are changing the country vale using the below specified code, State dropdown is not loading with corresponding values immediately.
   

$(

 

"#CustomerAddress_SelectedCountryForBillingAddress").val(tempProperty);

 

$(

 

"#CustomerAddress_SelectedCountryForBillingAddress-input").val(tempProperty);

 Client side OnChange() event which loads states in States dropdown is firing only after we click somewhere on the screen.

 Can someone address this soon?

 

5 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 28 Mar 2012, 12:58 PM
Hello Narayanarao,

We are not aware of such issue. I suggest you to send us a sample project which replicates the problem so we can investigate what exactly goes wrong.

Kind regards,
Petur Subev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
0
Narayanarao
Top achievements
Rank 1
answered on 03 Apr 2012, 05:44 AM

Hi team,

 Attached is the sample project you are asking for. Below are the steps to reproduce the issue after running the solution.

    1. Form is having 2 addresses "Address 1" and "Address 2" each having Country,State and City fields,
    2. If you select any country other than "United States",  State drop down will turn into a text box and vice versa.
    3. If you select "Address 2 same as Address 1" check box all the controls under Address 2 will get disabled and displays the data same as Address 1.
    4. Whenever there is any change in any of the fields of Address 1 will immediately reflect under Address 2.
    5. Now the problem is whenever there is a change in the Country dropdown of Address 1 corresponding State control  under Address 2 is not appearing immediately unless and until user clicks on any where of the form under Address 2.

Please suggest us the appropriate solution.

Regards,
0
Petur Subev
Telerik team
answered on 03 Apr 2012, 10:34 AM
Hi Narayanarao,

Thank you for sending the sample project. Basically the problem is that the logic toggling the BillingAddressStateProvinceRow and BillingAddressOtherStateRow is executed before you switch the values of the comboboxes.
Also I recommend you to use the value method to change the values of the ComboBox-es. 

Here is an example working in your case:

function copyPrimaryToBillingAddress() {
    var shippingCountryCombo = $("#Address_ShippingAddress_CountryCode").data('tComboBox');
    var shippingStateCombo = $("#Address_ShippingAddress_StateProvinceCode").data('tComboBox');
 
    var billingCountryCombo = $("#Address_BillingAddress_CountryCode").data('tComboBox');
    var billingStateCombo = $("#Address_BillingAddress_StateProvinceCode").data('tComboBox');
 
    billingCountryCombo.value(shippingCountryCombo.value());
    billingStateCombo.value(shippingStateCombo.value());
 
    if (billingCountryCombo.value() != "US") {
        $('#BillingAddressStateProvinceRow').hide();
        $('#BillingAddressOtherStateRow').show();
    }
    else {
        $('#BillingAddressStateProvinceRow').show();
        $('#BillingAddressOtherStateRow').hide();
    }
}


All the best,
Petur Subev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
0
Narayanarao
Top achievements
Rank 1
answered on 03 Apr 2012, 01:44 PM


 Hi Team,

    Thank you very much for you reply. The solution you suggested is working fine my sample application. But actual problem is I should be able to call client side events
    

OnChange(

 

"getStatesForBillingAddress") or OnClose("getStatesForBillingAddress")

immediately when "Address 2 same as Address 1" combobox is checked and on change of Country in Address 1 section.

The above specified client side events are calling once after we click somewhere on the form only.

Kindly suggest me the solution.

Regards,
Raju

 

0
Petur Subev
Telerik team
answered on 06 Apr 2012, 10:01 AM
Hi ,

Basically you can trigger the change event manually when the change of the shipping country ComboBox occurs.
e.g.
function getStatesForShippingAddress() {
        if ($('#BillingAddressSimilarToPrimary').is(':checked')) {
            $('#Address_BillingAddress_CountryCode').trigger('valueChange');
        }
    //...
}
You can use the same triggering code in the click handler of the checkbox.

Regards,
Petur Subev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
Tags
ComboBox
Asked by
Narayanarao
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Narayanarao
Top achievements
Rank 1
Share this question
or