Magento:获取用户选择的国家/地区

时间:2012-11-02 08:29:21

标签: php javascript magento

我有一段代码可以创建国家/地区的下拉列表

<div class="input-box">
   <?php $_countries = Mage::getResourceModel('directory/country_collection')->loadData()->toOptionArray(false) ?>
   <?php if (count($_countries) > 0): ?>
      <select name="country" id="country" onchange="print()">
         <option value=""> </option>
         <?php foreach($_countries as $_country): ?>
                <option value="<?php echo $_country['value'] ?>">
                    <?php echo $_country['label'] ?>
                </option>
             <?php endforeach; ?>
      </select>
   <?php endif; ?>
</div>

我无法弄清楚如何获得用户选择的国家/地区。你能帮我吗?

1 个答案:

答案 0 :(得分:1)

<div class="input-box">
<?php $_countries = Mage::getResourceModel('directory/country_collection')->loadData()->toOptionArray(false) ?>
<?php if (count($_countries) > 0): ?>
  <select name="country" id="country" onchange="showCountry(this)">
     <option value=""> </option>
        <option value="<?php echo $_country['value'] ?>" <?php echo $select; ?> >
            <?php echo $_country['label'] ?>
        </option>
     <?php endforeach; ?>       </select>
 <?php endif; ?>
</div>

function showCountry​(ele){
  alert(ele.value);
}  ​