11 Replies Latest reply on Oct 16, 2009 4:34 PM by kglad

    Drop Down menu help needed

    xranerx

      Hi, on my site at the checkout page, it has 2 drop down menus, one for country and one for state.  right now as it is, if you select United States from the first menu, you are then able to select which state you are from.  But if any other country is selected, the Select State drop down menu dissappears.  The coding looks like this right now

       

      private function onChange(target:SelectCountryCombo):Void {
        switch(target) {
         case _selectCountry:
          if (target.value == 'US')
           _selectState.visible = true      
          else
           _selectState.visible = false;
         break;
        }

       

      What i want to do is make it so that if you select canada the drop down menu stays visable, and i've added the provinces into the list.  I tried adding 'CA' along with the 'US' but that makes it stay visible for all countries, i only want it visible for the 2.  it seems easy but i really dont know action script very well at all.  Thanks a lot for any  help

        • 1. Re: Drop Down menu help needed
          kglad Adobe Community Professional & MVP

          use:

           

           


           

          private function onChange(target:SelectCountryCombo):Void {
            switch(target) {
             case _selectCountry:
              if (target.value == 'US' || target.value=="CA")
               _selectState.visible = true      
              else
               _selectState.visible = false;
             break;
            }

           

           

          • 2. Re: Drop Down menu help needed
            xranerx Level 1

            that worked thanks again!

            • 3. Re: Drop Down menu help needed
              kglad Adobe Community Professional & MVP

              you're welcome.

              • 4. Re: Drop Down menu help needed
                xranerx Level 1

                I just had another question about the same thing. Is it possible that when CA is selected, that a different data provider for the "Select State" list would come up? For example, if US were selected it would load "_selectState.dataProvider = PayPalStateUSList.instance.option;" but if CA were selected, i could have it load the same thing but with just provinces? i tried to just copy the coding for PayPalStateUSList and rename it PayPalStateCAList with the list changed to provinces, and have it load it in the as but i dont really know what im doing.

                 

                right now i just have the states and provinces all in one list, but its just harder to select when everything is all mixed in. it looks a bit unorganized.

                 

                 

                another thing i would like to do, is change the total price based on the country selected in the drop down menu, if its possible. right now I have a shipping charge being added to the total from the shopping cart screen (thanks to kglad), but what would make more sence would to have the shipping based on wether its domestic or international. would it be possible to change the total based on the country selected?

                 

                these are the last of my questions, after these 2 issues are fixed my site is complete.  Thanks for all the help

                 

                 

                The coding for the page looks like this (both my concerns are on the same page)

                 

                 

                 

                import mx.utils.Delegate;
                import kliment.managers.PopUpManager;
                import kliment.data.FormField;
                import kliment.display.MCC;
                import kliment.net.URL;
                import kliment.net.URLMethod;
                import kliment.net.URLTarget;
                import kliment.utils._Object;
                import kliment.utils._String;

                import as.Application;
                import as.Settings;
                import as.SimpleButton;
                import as.subpage.elements.AgreeCheckBox;
                import as.subpage.elements.SelectStateCombo;
                import as.subpage.SubpageAbstract;
                import as.menu.Menu;
                import as.AlertMessage;
                import as.shopingcart.PayPalCountryList;
                import as.shopingcart.PayPalStateUSList;
                import as.subpage.elements.SelectCountryCombo;
                import as.subpage.elements.SelectCountryItemRender;
                /**
                * ...
                * @author ...
                */
                class as.subpage.ViewCheckout extends SubpageAbstract {
                private var _IDENTIFIER:String = 'checkout_view';

                private var _price_txt:TextField;
                private var _f_name_txt:FormField;
                private var _l_name_txt:FormField;
                private var _email_txt:FormField;
                private var _phone_txt:FormField;
                private var _city_txt:FormField;
                private var _street_txt:FormField;
                private var _zip_txt:FormField;
                private var _country_cb:FormField;
                private var _state_cb:FormField;
                private var _selectCountry:SelectCountryCombo;
                private var _selectState:SelectCountryCombo;
                private var _i_agree_cb:AgreeCheckBox;
                private var _proceed_btn:SimpleButton;

                public function ViewCheckout() {
                  super();
                }

                private function _init():Void {
                  _target_mc = MCC.attach(_IDENTIFIER, _host.content_mc);
                  _page_mc = _target_mc.page_mc;
                 
                  _price_txt = _page_mc.price_txt;
                  _price_txt.autoSize = 'left';
                  _price_txt.text = Settings.CURRENCY + _String.decimalFractions(Application.instance.aSopingCart.totalPrice, 2);
                 
                  _f_name_txt = new FormField(_page_mc.f_name_txt, 'first_name', _page_mc.f_name_txt.text, true);
                  _l_name_txt = new FormField(_page_mc.l_name_txt, 'last_name', _page_mc.l_name_txt.text, true);
                  _city_txt = new FormField(_page_mc.city_txt, 'city', _page_mc.city_txt.text, true);
                  _street_txt = new FormField(_page_mc.street_txt, 'address1', _page_mc.street_txt.text, true);
                  _zip_txt = new FormField(_page_mc.zip_txt, 'zip', _page_mc.zip_txt.text, true);
                 
                  _email_txt = new FormField(_page_mc.email_txt, 'email', _page_mc.email_txt.text, true);
                  _phone_txt = new FormField(_page_mc.phone_txt, 'night_phone_b', _page_mc.phone_txt.text);
                 
                  _selectCountry = new SelectCountryCombo(_page_mc.select_country_mc, 'combo_box_list', 'Select a country');
                  _selectCountry.itemRender = SelectCountryItemRender;
                  _selectCountry.dataProvider = PayPalCountryList.instance.option;
                  _selectCountry.addListener(this);
                 
                  _selectState = new SelectCountryCombo(_page_mc.select_state_mc, 'combo_box_list', 'Select a state');
                  _selectState.itemRender = SelectCountryItemRender;
                  _selectState.dataProvider = PayPalStateUSList.instance.option;
                  _selectState.addListener(this);
                 
                  _country_cb = new FormField(_selectCountry, 'adress_country', '', true);
                  _state_cb = new FormField(_selectState, 'adress_state', ''); 
                 
                  _proceed_btn = new SimpleButton(_page_mc.proceed_mc);
                  _proceed_btn.onClick = Delegate.create(this, _onProceedClickHandler);
                 
                  _i_agree_cb = new AgreeCheckBox(_page_mc.i_agree_mc);
                 
                  _page_mc.f_name_txt.tabIndex = 0;
                  _page_mc.l_name_txt.tabIndex = 1;
                  _page_mc.email_txt.tabIndex = 2;
                  _page_mc.phone_txt.tabIndex = 3;
                  _page_mc.zip_txt.tabIndex = 4;
                  _page_mc.city_txt.tabIndex = 5;
                  _page_mc.street_txt.tabIndex = 6;
                 
                  _page_mc._y = 33;
                  _page_mc._x = 50;
                }

                private function onChange(target:SelectCountryCombo):Void {
                  switch(target) {
                   case _selectCountry:
                    if (target.value == 'US' || target.value=="CA")
                     _selectState.visible = true      
                    else
                     _selectState.visible = false;
                   break;
                  }
                }

                private function _onProceedClickHandler():Void {
                  var isError:Boolean = false;
                  var isErrorSelect:Boolean = false;
                  var message:String = '';
                  var messageLine1:String = '';
                  var messageLine2:String = '';
                 
                  var forSend:Object = new Object();
                  forSend.cmd = '_cart';
                  forSend.business = Settings.BUSINESS_EMAIL;
                  forSend.currency_code = Settings.CURRENCY_CODE;
                  forSend.upload = 1;
                  forSend.address_override = 1;
                  forSend.rm = 2;
                  forSend.no_shipping = 1;
                 
                  if (Settings.NOTIFY_URL)
                  forSend.notify_url = Settings.NOTIFY_URL;
                 
                  if (Settings.RETURN_URL)
                  forSend.return_url = Settings.RETURN_URL;
                  
                  var purchasesList:Object = Application.instance.aSopingCart.getPayPalCarts();
                  if (!purchasesList) {
                   isError = true;
                   message += 'The shopping cart is empty.'+newline;
                  }
                 
                  if (_f_name_txt.isValid)
                   forSend[_f_name_txt.name] = _f_name_txt.value;
                  else {
                   messageLine1 += ((isError)?', ':'') + String(_f_name_txt.start_value).toLowerCase();
                   isError = true;
                  }
                 
                  if (_l_name_txt.isValid)
                   forSend[_l_name_txt.name] = _l_name_txt.value;
                  else {
                   messageLine1 += ((isError)?', ':'') + String(_l_name_txt.start_value).toLowerCase();
                   isError = true;
                  }
                 
                  if (_email_txt.isValid)
                   forSend[_email_txt.name] = _email_txt.value;
                  else {
                   messageLine1 += ((isError)?', ':'') + String(_email_txt.start_value).toLowerCase();
                   isError = true;
                  }
                 
                  if (_phone_txt.isValid)
                   forSend[_phone_txt.name] = _phone_txt.value;
                  else {
                   messageLine1 += ((isError)?', ':'') + String(_phone_txt.start_value).toLowerCase();
                   isError = true;
                  }
                 
                  if (_city_txt.isValid)
                   forSend[_city_txt.name] = _city_txt.value;
                  else {
                   messageLine1 += ((isError)?', ':'') + String(_city_txt.start_value).toLowerCase();
                   isError = true;
                  }
                 
                  if (_street_txt.isValid)
                   forSend[_street_txt.name] = _street_txt.value;
                  else {
                   messageLine1 += ((isError)?', ':'') + String(_street_txt.start_value).toLowerCase();
                   isError = true;
                  }
                 
                  if (_zip_txt.isValid)
                   forSend[_zip_txt.name] = _zip_txt.value;
                  else {
                   messageLine1 += ((isError)?', ':'') + String(_zip_txt.start_value).toLowerCase();
                   isError = true;
                  }
                 
                  if (isError)
                   messageLine1 = 'Please enter your ' + messageLine1 + '. ' + newline;
                 
                  if (_selectCountry.selectedIndex >= 0)
                   forSend['country_code'] = _selectCountry.value;
                  else {
                   messageLine2 += ((isErrorSelect)?', ':'') + 'country';
                   isError = true;
                   isErrorSelect = true;
                  }
                 
                  if (_selectState.selectedIndex >= 0 && _selectCountry.value == 'US')
                   forSend['state'] = _selectState.value;
                  else if (_selectCountry.value == 'US'){
                   messageLine2 += ((isErrorSelect)?', ':'') + 'state';
                   isError = true;
                   isErrorSelect = true;
                  }
                 
                  if (isErrorSelect)
                   messageLine2 = 'Please select your ' + messageLine2 + '. ' + newline;
                 
                  //isError = false;
                  if (!isError && Boolean(_i_agree_cb.value)) {
                   _Object.copyTo(purchasesList, forSend);
                  
                   URL.navigate('https://www.paypal.com/cgi-bin/webscr', forSend, URLMethod.POST, URLTarget.BLANK);
                   Application.instance.aSopingCart.clear();
                   message = 'The purchases are waiting for the payment.'+newline+'The shopping cart is empty.';
                   _application.gotoSpash();
                  } else {
                   message += 'You need to accept The Terms of Use to place an order. ' + newline;
                  }
                 
                  message += messageLine1;
                  message += messageLine2;
                 
                  new AlertMessage('Info!', message);
                }

                public function onResize():Void {
                 
                }
                }

                • 5. Re: Drop Down menu help needed
                  kglad Adobe Community Professional & MVP

                  yes, to both.  you can assign your state combobox a dataprovider dynamically (ie, based on the country combobox'es value) and you can use variables whose value is based on country for both your fixed amount to add to shipping and for your shipping factor.

                  • 6. Re: Drop Down menu help needed
                    xranerx Level 1

                    Would you be able to show me what the coding would be like? I've been messing with it but haven't been able to get the results I'm looking for.  Thanks for helping me out

                    • 7. Re: Drop Down menu help needed
                      kglad Adobe Community Professional & MVP

                      for example, if your country combobox has instance name countryCB (where the U.S. has index 0 and CA has index 1) and your state combobox has instance name stateCB and you have an array of U.S. states (say a0) and an array of CA provences (say a1), you can use:

                       

                      stateCB.dataProvider=this["a"+countryCB.selectedIndex];

                      1 person found this helpful
                      • 8. Re: Drop Down menu help needed
                        xranerx Level 1

                        that makes sence, though im not sure how to make my state list an array. i tried reading tutorials on it but i cant seem to figure it out without making the whole list disappear completely.  i will do more reading though and try to figure it out though, so thank you for your help.

                         

                        would you be able to let me know about how to change the total based on the country chosen? would that be done using the coding on that page that i posted?

                        • 9. Re: Drop Down menu help needed
                          kglad Adobe Community Professional & MVP

                          flash can convert your state list to an array.  what format is it in now?

                           

                          as best i remember your shipping situation, you can use:

                           

                          CAfactor=1.2;

                          USfactor=1.1;

                           

                          CAflatrate=10;

                          USflatrate=0;

                           

                          if(CA){

                          factor=CAfactor;

                          flatrate=CAflatrate;

                          } else {
                          factor=USfactor;

                          flatrate=USflatrate

                          }

                           

                          total=0;

                          (for-loop running through all items to be shipped){
                          total+=factor*itemprice*itemnumber

                          }

                          total+=flatrate;

                          • 10. Re: Drop Down menu help needed
                            xranerx Level 1

                            the format of my us states list is like this. right now i just have the canadian provinces mixed in alphabetically

                             

                             

                             

                            import kliment.data.FastXML;
                            /**
                            * ...
                            * @author ...
                            */
                            class as.shopingcart.PayPalStateUSList extends FastXML{
                            static private var _instance:PayPalStateUSList;
                            static public function get instance():PayPalStateUSList {
                              if (!_instance)
                               _instance = new PayPalStateUSList();
                              return _instance;
                            }

                            public function PayPalStateUSList() {
                              super(new XML('<select><option value="AL">Alabama</option><option value="AK">Alaska</option><option value="AB">Alberta</option><option value="AZ">Arizona</option><option value="AR">Arizona</option><option value="BC">British Columbia</option><option value="CA">California</option><option value="CO">Colorado</option><option value="CT">Connecticut</option><option value="DC">District of Columbia</option><option value="DE">Delaware</option><option value="FL">Florida</option><option value="GA">Georgia</option><option value="HI">Hawaii</option><option value="ID">Idaho</option><option value="IL">Illinois</option><option value="IN">Indiana</option><option value="IA">Iowa</option><option value="KS">Kansas</option><option value="KY">Kentucky</option><option value="LA">Louisiana</option><option value="ME">Maine</option><option value="MB">Manitoba</option><option value="MD">Maryland</option><option value="MA">Massachusetts</option><option value="MI">Michigan</option><option value="MN">Minnesota</option><option value="MS">Mississippi</option><option value="MO">Missouri</option><option value="MT">Montana</option><option value="NE">Nebraska</option><option value="NV">Nevada</option><option value="NB">New Brunswick</option><option value="NL">Newfoundland & Labrador</option><option value="NH">New Hampshire</option><option value="NJ">New Jersey</option><option value="NM">New Mexico</option><option value="NY">New York</option><option value="NC">North Carolina</option><option value="ND">North Dakota</option><option value="NT">Northwest Territories</option><option value="NS">Nova Scotia</option><option value="NU">Nunavut</option><option value="OH">Ohio</option><option value="OK">Oklahoma</option><option value="ON">Ontario</option><option value="OR">Oregon</option><option value="PA">Pennsylvania</option><option value="PE">Prince Edward Island</option><option value="QC">Quebec</option><option value="RI">Rhode Island</option><option value="SK">Saskatchewan</option><option value="SC">South Carolina</option><option value="SD">South Dakota</option><option value="TN">Tennessee</option><option value="TX">Texas</option><option value="UT">Utah</option><option value="VT">Vermont</option><option value="VA">Virginia</option><option value="WA">Washington</option><option value="WV">West Virginia</option><option value="WI">Wisconsin</option><option value="WY">Wyoming</option><option value="YT">Yukon</option><option value="AA">Armed Forces Americas</option><option value="AE">Armed Forces</option><option value="AP">Armed Forces Pacific</option><option value="AS">American Samoa</option><option value="FM">Federated States of Micronesia</option><option value="GU">Guam</option><option value="MH">Marshall Islands</option><option value="MP">Northern Mariana Islands</option><option value="PR">Puerto Rico</option><option value="PW">Palau</option><option value="VI">Virgin Islands</option><option value=" "> </option></select>').firstChild);
                            }

                            }

                             

                             

                            and the last code you showed me for making 2 different shipping rates makes sence as i read it, i just dont know where it would go in my coding.  would you be able to show me where it goes in the coding in my above post? i really appreciate the help i have no idea what im doing.

                            • 11. Re: Drop Down menu help needed
                              kglad Adobe Community Professional & MVP

                              show your code that currently calculates shipping.

                               

                              here's your two lists

                               

                              caXML:XML="<prov><option value="AB">Alberta</option>,<option value="BC">British Columbia</option>,<option value="MB">Manitoba</option>,<option value="NB">New Brunswick</option>,<option value="NL">Newfoundland &amp; Labrador</option>,<option value="NT">Northwest Territories</option>,<option value="NS">Nova Scotia</option>,<option value="NU">Nunavut</option>,<option value="ON">Ontario</option>,<option value="PE">Prince Edward Island</option>,<option value="QC">Quebec</option>,<option value="SK">Saskatchewan</option>,<option value="YT">Yukon</option>,<option value="AA">Armed Forces Americas</option>,<option value="AE">Armed Forces</option>,<option value="AP">Armed Forces Pacific</option></prov>".split(",").join("");

                               

                              usXML:XML="<states><option value="AL">Alabama</option>,<option value="AK">Alaska</option>,<option value="AZ">Arizona</option>,<option value="AR">Arizona</option>,<option value="CA">California</option>,<option value="CO">Colorado</option>,<option value="CT">Connecticut</option>,<option value="DC">District of Columbia</option>,<option value="DE">Delaware</option>,<option value="FL">Florida</option>,<option value="GA">Georgia</option>,<option value="HI">Hawaii</option>,<option value="ID">Idaho</option>,<option value="IL">Illinois</option>,<option value="IN">Indiana</option>,<option value="IA">Iowa</option>,<option value="KS">Kansas</option>,<option value="KY">Kentucky</option>,<option value="LA">Louisiana</option>,<option value="ME">Maine</option>,<option value="MD">Maryland</option>,<option value="MA">Massachusetts</option>,<option value="MI">Michigan</option>,<option value="MN">Minnesota</option>,<option value="MS">Mississippi</option>,<option value="MO">Missouri</option>,<option value="MT">Montana</option>,<option value="NE">Nebraska</option>,<option value="NV">Nevada</option>,<option value="NH">New Hampshire</option>,<option value="NJ">New Jersey</option>,<option value="NM">New Mexico</option>,<option value="NY">New York</option>,<option value="NC">North Carolina</option>,<option value="ND">North Dakota</option>,<option value="OH">Ohio</option>,<option value="OK">Oklahoma</option>,<option value="OR">Oregon</option>,<option value="PA">Pennsylvania</option>,<option value="RI">Rhode Island</option>,<option value="SC">South Carolina</option>,<option value="SD">South Dakota</option>,<option value="TN">Tennessee</option>,<option value="TX">Texas</option>,<option value="UT">Utah</option>,<option value="VT">Vermont</option>,<option value="VA">Virginia</option>,<option value="WA">Washington</option>,<option value="WV">West Virginia</option>,<option value="WI">Wisconsin</option>,<option value="WY">Wyoming</option>,<option value="AS">American Samoa</option>,<option value="FM">Federated States of Micronesia</option>,<option value="GU">Guam</option>,<option value="MH">Marshall Islands</option>,<option value="MP">Northern Mariana Islands</option>,<option value="PR">Puerto Rico</option>,<option value="PW">Palau</option>,<option value="VI">Virgin Islands</option></states>".split(",").join("");