Announcement

Collapse
No announcement yet.

State/Country Dropdown not defaulting to previously saved choice

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • State/Country Dropdown not defaulting to previously saved choice

    Because of all the CSSing I'm doing on my site, I ended up hardcoding the State and Country dropdown lists on all the pages that use them.

    The issue I am having is that, if a user creates an account and saves his/her information it is fine. But, when the user comes back later to edit or view their information, all my dropdowns are back to the original default value (and not what the customer had saved).

    How can I get the State and Country dropdowns to reflect what is saved for the user in the Database (like all the other fields) and not go back to the defaulted value?

    Here is the code I have hardcoded for state (similar for country):

    [CODE]
    <select name="ShipState" value="&mvte:global:ShipState;" STYLE="color:#1A4570;font-size:10px"
    <mvt:if expr="NOT g.ShipState_Invalid">
    class="formpulldown245">
    <mvt:else>
    class="formpulldownrequired245">
    </mvt:if>
    <OPTION VALUE = "" SELECTED>Outside US</OPTION>
    <OPTION VALUE = "AK">Alaska</OPTION>
    <OPTION VALUE = "AL">Alabama</OPTION>
    <OPTION VALUE = "AR">Arkansas</OPTION>
    ....
    <OPTION VALUE = "WV">West Virginia</OPTION>
    <OPTION VALUE = "WY">Wyoming</OPTION>
    </SELECT>
    [CODE]


    Thank you for your help.

  • Re: State/Country Dropdown not defaulting to previously saved choice

    Code:
    <mvt:comment>Use built in state selection if logged in</mvt:comment>
    <mvt:if expr="g.Basket:CUST_ID">
    <mvt:item name="states" param="ShipStateSelect" />
    <mvt:else>
    <select name="ShipState" value="&mvte:global:ShipState;" STYLE="color:#1A4570;font-size:10px"
    <mvt:if expr="NOT g.ShipState_Invalid">
    class="formpulldown245">
    <mvt:else>
    class="formpulldownrequired245">
    </mvt:if>
    <OPTION VALUE = "" SELECTED>Outside US</OPTION>
    <OPTION VALUE = "AK">Alaska</OPTION>
    <OPTION VALUE = "AL">Alabama</OPTION>
    <OPTION VALUE = "AR">Arkansas</OPTION>
    ....
    <OPTION VALUE = "WV">West Virginia</OPTION>
    <OPTION VALUE = "WY">Wyoming</OPTION>
    </SELECT>
    </mvt:if>

    Comment


    • Re: State/Country Dropdown not defaulting to previously saved choice

      Hi Leanne,

      Thanks for your reply.

      The problem with the built in state selection is that I cannot control the format of the box (my CSS stuff). It just puts a plain white box on the screen and I don't have access to the code that writes it (or do i?).

      What I would like to be able to do is still use the dropdown but have it default to the value of whatever it has in &mvte:global:ShipState.

      The only way I can think to do this is to have 50 if statements and then to place a "Selected" conditionally depending on if hte value in &mvte:global:ShipState equals the value of the option. There must be another way?

      Comment


      • Re: State/Country Dropdown not defaulting to previously saved choice

        This is the site, in case it is easier to see the problem I am having:

        http://209.216.253.28/mm5/merchant.m...e_Code=Chicago

        Comment


        • Re: State/Country Dropdown not defaulting to previously saved choice

          Could you apply the class to the table cell instead?

          Code:
          <mvt:comment>Use built in state selection if logged in</mvt:comment>
          <mvt:if expr="g.Basket:CUST_ID">
          <td
          <mvt:if expr="NOT g.ShipState_Invalid">
          class="formpulldown245">
          <mvt:else>
          class="formpulldownrequired245">
          </mvt:if>
          <mvt:item name="states" param="ShipStateSelect" />
          </td>
          <mvt:else>
          <td>
          <select name="ShipState" value="&mvte:global:ShipState;" STYLE="color:#1A4570;font-size:10px"
          <mvt:if expr="NOT g.ShipState_Invalid">
          class="formpulldown245">
          <mvt:else>
          class="formpulldownrequired245">
          </mvt:if>
          <OPTION VALUE = "" SELECTED>Outside US</OPTION>
          <OPTION VALUE = "AK">Alaska</OPTION>
          <OPTION VALUE = "AL">Alabama</OPTION>
          <OPTION VALUE = "AR">Arkansas</OPTION>
          ....
          <OPTION VALUE = "WV">West Virginia</OPTION>
          <OPTION VALUE = "WY">Wyoming</OPTION>
          </SELECT>
          </td>
          </mvt:if>
          Then add something like:

          td.pulldown245 select {styles here }
          td.pulldownrequired 245 select {other styles here }

          Edited to add: For that matter, doing it this way, you could get rid of the hard-coded drop down altogether if all you need is the ability to apply the css to the select tag within that particular cell.
          Last edited by Leanne; 11-07-07, 06:06 AM.

          Comment


          • Re: State/Country Dropdown not defaulting to previously saved choice

            I tried setting the class based on the validation of the field and then calling the stateselect item.

            The class attributes don't pass over to the stateselect item, so when it generates its own code, it creates its own Select and Options (and ignores my Class statement).

            Unless I am doing it wrong.

            Comment


            • Re: State/Country Dropdown not defaulting to previously saved choice

              did you try adding a TD style, then create a class called MyDropDown....wrap the state select dropdown with div class=MyDropDown.
              Bruce Golub
              Phosphor Media - "Your Success is our Business"

              Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
              phosphormedia.com

              Comment


              • Re: State/Country Dropdown not defaulting to previously saved choice

                I think what they are recommending you to do is use the parent cell as a selector:
                td.formpulldown245 select {
                color: #F00;
                }
                or
                div.MyDropDown select {
                color: #00F;
                }

                Comment


                • Re: State/Country Dropdown not defaulting to previously saved choice

                  I ended up just using a javascript function to select it based on the value in the mvt global variable . . seems to work great.

                  In case anyone's interested, this is what I added at the bottom of my <body> section:


                  <script type="text/javascript">
                  function prepopulateDropdown(menuName, userSelection) {
                  var dropdownMenu = document.getElementById(menuName);
                  for (var i = 0; i < dropdownMenu.options.length; i++) {
                  if (dropdownMenu.options[i].value == userSelection) {
                  dropdownMenu.options[i].selected = true;
                  return true;
                  }
                  }
                  }
                  function prepopulateDropdown2(menuName, userSelection) {
                  var dropdownMenu = document.getElementById(menuName);
                  userSelection = userSelection.substring(0,2);
                  for (var i = 0; i < dropdownMenu.options.length; i++) {
                  if (dropdownMenu.options[i].value == userSelection) {
                  dropdownMenu.options[i].selected = true;
                  return true;
                  }
                  }
                  }
                  prepopulateDropdown("Customer_ShipCountry", "&mvte:global:Customer_ShipCountry;");
                  prepopulateDropdown("Customer_BillCountry", "&mvte:global:Customer_BillCountry;");
                  prepopulateDropdown2("Customer_ShipState", "&mvte:global:Customer_ShipState;");
                  prepopulateDropdown2("Customer_BillState", "&mvte:global:Customer_BillState;");
                  </script>

                  Comment


                  • Re: State/Country Dropdown not defaulting to previously saved choice

                    Hi, I have same basic issue, the country/state don't load saved values properly. I see the javascript solution but I'm a bit concerned that not everybody has javascript installed on their browser. Is it considered a reliable solution to use javascript?

                    Can anybody give me solution just using the miva interface on how to select this stuff properly? I don't quite see how to implement the above suggested code, where is this going in the checkout: customer information page? Is there a "dummies" guide somewhere on how to make this fix that I can refer to?

                    Thanks!

                    Comment


                    • Re: State/Country Dropdown not defaulting to previously saved choice

                      Have you modified the country and state selections? If you're using the built in ones, you shouldn't be having this problem.

                      Comment


                      • Re: State/Country Dropdown not defaulting to previously saved choice

                        Modified? No, its using the built in ones! The only thing I did is add a little Javascript for validation but that only kicks in if there is an error and it doesn't change the selection at all.

                        Comment


                        • Re: State/Country Dropdown not defaulting to previously saved choice

                          Can you post your template code?

                          Comment


                          • Re: State/Country Dropdown not defaulting to previously saved choice

                            Sure, why not, lots of header code in here:

                            <html>
                            <head>
                            <title>&mvt:store:name;: Checkout: Customer Information</TITLE>
                            <base href="&mvt:global:basehref;">
                            <mvt:item name="head" />
                            <link rel="stylesheet" href="https://www.abraham-hicks.com/css/global.css" media="screen" title="abraham-hicks" />
                            <script type="text/javascript" src="<A href="https://www.abraham-hicks.com/jscript/detect_flash.js"></script">https://www.abraham-hicks.com/jscript/detect_flash.js"></script>
                            <script type="text/javascript" src="<A href="https://www.abraham-hicks.com/jscript/swap_secure.js"></script">https://www.abraham-hicks.com/jscript/swap_secure.js"></script>
                            <script type="text/javascript">
                            function validate_form(thisform)
                            {
                            with (thisform)
                            {
                            if ((ShipStateSelect.value == "") && (ShipCountry.value == "US"))
                            {
                            alert("You can not specify state as 'Outside US' when country is set as 'United States'. Please select either a state or a different country and try again!");
                            ShipStateSelect.focus();
                            return false;
                            }
                            if ((ShipStateSelect.value != "") && (ShipCountry.value != "US"))
                            {
                            alert("If you specify a State then the country must be set to 'United States'. Your country selection will be changed to 'United States', please make corrections as needed!");
                            ShipCountry.focus();
                            return false;
                            }
                            }
                            }
                            </script>
                            </head>
                            <body id="sub2" class="sub">
                            <div id="wrapper">
                            <div id="header">
                            <h1><a href="<A href="http://www.abraham-hicks.com/index.php">Abraham-Hicks">http://www.abraham-hicks.com/index.php">Abraham-Hicks Publications</a></h1>
                            <em class="alt">You are loved. All is well.</em>
                            <ul id="access">
                            <li><a href="<A href="http://www.abraham-hicks.com/fulltextsearch.php">Search</a></li">http://www.abraham-hicks.com/fulltextsearch.php">Search</a></li>
                            <li><a href="&mvt:global:sessionurl;Store_Code=&mvta:stor e:code;&Screen=PLST">Product List</a></li>
                            <li><a href="&mvt:global:secure_sessionurl;Store_Code=&mv ta:store:code;&Screen=BASK">Basket</a></li>
                            <li><a href="&mvt:global:secure_sessionurl;Store_Code=&mv ta:store:code;&Screen=OINF">Checkout</a></li>
                            <li><a href="<A href="http://www.abraham-hicks.com/contact.php">Contact">http://www.abraham-hicks.com/contact.php">Contact Us</a></li>
                            <li><a href="<A href="http://www.abraham-hicks.com/index.php">Home</a></li">http://www.abraham-hicks.com/index.php">Home</a></li>
                            </ul>
                            <div id="nav">
                            <noscript>
                            <div id="noflash_nav">
                            <map name="nav">
                            <area shape="rect" coords="29,14,93,57" href="http://www.abraham-hicks.com/teachings.php" target="_self" alt="Abraham Teachings" />
                            <area shape="rect" coords="163,29,209,53" href="http://www.abraham-hicks.com/mm5/merchant.mvc" target="_self" alt="Store" />
                            <area shape="rect" coords="277,14,344,58" href="http://www.abraham-hicks.com/journal.php" target="_self" alt="Quarterly Journals" />
                            <area shape="rect" coords="388,29,486,54" href="https://www.abraham-hicks.com/subscriptions.php" target="_self" alt="Subscriptions" />
                            <area shape="rect" coords="520,15,598,59" href="http://www.abraham-hicks.com/workshops.php" target="_self" alt="Workshops and Cruises" />
                            <area shape="rect" coords="661,19,708,61" href="http://www.abraham-hicks.com/about_us.php" target="_self" alt="About Us" />
                            </map>
                            <img src="https://www.abraham-hicks.com/images/nav.gif" width="750" height="83" usemap="#nav" border="0">
                            </div>
                            </noscript>
                            </div>
                            </div>
                            <div id="content">
                            <mvt:item name="hdft" param="global_header" />
                            <table border="0" cellpadding="0" cellspacing="0" width="100%">
                            <tr><td align="left" valign="bottom">
                            <mvt:item name="hdft" param="header" />
                            </td></tr>
                            <form method="POST" onsubmit="return validate_form(this)" action="&mvt:global:secure_sessionurl;">
                            <mvt:if expr="l.settings:basket:total GT 0">
                            <input type="hidden" name="Action" value="ORDR">
                            <input type="hidden" name="Screen" value="OUSL">
                            <mvt:elseif expr="g.Store:req_frship">
                            <input type="hidden" name="Action" value="ORDR">
                            <input type="hidden" name="Screen" value="OSEL">
                            <mvt:else>
                            <input type="hidden" name="Action" value="ORDR,SHIP,CTAX,AUTH">
                            <input type="hidden" name="Screen" value="INVC">
                            </mvt:if>
                            <input type="hidden" name="Store_Code" value="&mvte:store:code;">
                            <tr><td align="left" valign="top" width="100%">
                            <br>
                            <mvt:item name="fonts" param="body_font">
                            <mvt:item name="messages" />
                            </mvt:item>
                            <mvt:item name="basket" />
                            <mvt:item name="fonts" param="body_font">
                            <mvt:item name="customer" />
                            <mvt:item name="brokups_resident" />
                            </mvt:item>
                            </td></tr>
                            <tr><td align="right">

                            <mvt:item name="addendum" param="ocst" />
                            <mvt:item name="fonts" param="body_font">
                            <mvt:item name="buttons" param="Continue" />
                            </mvt:item>
                            </td></tr>
                            </form>
                            <tr><td align="right">
                            <mvt:item name="ads_continueshopping" param="contshop_button" />
                            </td></tr>
                            <tr><td align="left" valign="bottom">
                            <mvt:item name="hdft" param="footer" />
                            </td></tr>
                            </table>
                            <mvt:item name="hdft" param="global_footer" />
                            </div>
                            <div id="footer">
                            <ul>
                            <li><a href="<A href="http://www.abraham-hicks.com/contact.php">Contact">http://www.abraham-hicks.com/contact.php">Contact Us</a></li>
                            <li><a href="<A href="http://www.abraham-hicks.com/fulltextsearch.php">Search</a></li">http://www.abraham-hicks.com/fulltextsearch.php">Search</a></li>
                            <li><a href="<A href="http://www.abraham-hicks.com/abehicksfaq.php">FAQ</a></li">http://www.abraham-hicks.com/abehicksfaq.php">FAQ</a></li>
                            <li><a href="&mvt:global:secure_sessionurl;Store_Code=&mv ta:store:code;&Screen=BASK">Basket</a></li>
                            <li><a href="<A href="http://www.abraham-hicks.com/sitemap.php">Site">http://www.abraham-hicks.com/sitemap.php">Site Map</a></li>
                            </ul>
                            <p>&copy;1997-2007 Abraham-Hicks Publications.</p>
                            </div>
                            </div>
                            </html>

                            Comment


                            • Re: State/Country Dropdown not defaulting to previously saved choice

                              I think most browsers are capable of javascript. I tested with IE 6 and 7, firefox and safari and all were able to handle it.

                              As far as code placement, I just put the function declaration at the bottom of the page and then the function calls (which you can see . . the four times I call the function . . immediately after the function declaration).

                              This seems to work for me . .

                              Comment

                              Working...
                              X