1

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.

2 Answers 2

2

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.

2
  • No javascript errors reported in the console. Also, the javascript in your answer is the right place on the page - I haven't modified that. When I submit the billing form, validation obviously will fail, and when I get "redirected", the state field will show up (with all the states populated). Any other ideas?
    – Vee
    Commented Jul 20, 2015 at 21:09
  • 1
    You were right! The code that I was working on already had a previous edit that I was not aware of. But, when the page "refreshed", the error in the JS console went away as well which is why I couldn't catch the problem. Thanks!
    – Vee
    Commented Jul 21, 2015 at 18:15
1

I'm not sure the file you are editing is the right one. Enable Template path hints and you will be able to see if the template is the right one.

You can also check System > Configuration > Genera > States Options

2
  • I'm definitely looking at the right template as indicated by path hints and also because changes to the template are reflected when I reload the page.
    – Vee
    Commented Jul 20, 2015 at 21:10
  • Also, checked the "States Options" tab, and "Display not required State" = Yes. Also, the US is selected in the "State is required for" dropdown which is the default country selected in the billing form.
    – Vee
    Commented Jul 20, 2015 at 21:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.