Magento 1.9 – Fix ‘State’ Field Not Displaying in Checkout Forms

javascriptmagento-1.9onepage-checkout

I'm using Magento 1.9 and can't figure out why the state field in the billing and shipping forms used in the onepage checkout process don't show up. Here's the code for the billing form:

frontend/default/mycompany/template/persistent/checkout/onepage/billing.phtml:

<div class="input-box">
    <select id="billing:region_id" name="billing[region_id]" title="<?php echo $this->__('State/Province') ?>" class="validate-select" style="display:none;">
        <option value=""><?php echo $this->__('State/Province') ?></option>
    </select>
    <script type="text/javascript">
        //<![CDATA[
        $('billing:region_id').setAttribute('defaultValue',  "<?php echo $this->getAddress()->getRegionId() ?>");
        //]]>
    </script>
    <input type="text" id="billing:region" name="billing[region]" value="<?php echo $this->escapeHtml($this->getAddress()->getRegion()) ?>"  title="<?php echo $this->__('State/Province') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('region') ?>" placeholder="<?php echo $this->__('State/Province') ?>" style="display:none;" /></div>

Even if I remove the inline styling in the tag, style="display:none;", the field still doesn't show up.

  1. Where is the javascript file that is controlling the show/hide function of this field? The JS script is setting an attribute to a default value; however, the php code, getAddress()->getRegionId() ?>, yields a blank.

  2. Is there a setting in the Admin panel that controls whether or not this field is displayed? The default country is set for the US.

Best Answer

Are there any JavaScript errors? The javascript to actually populate and show the form should be lower on the page and should look something like this:

var billingRegionUpdater = new RegionUpdater('billing:country_id', 'billing:region', 'billing:region_id', <?php echo $this->helper('directory')->getRegionJson() ?>, undefined, 'billing:postcode');

You should check to see if that code is present and running correctly.