Curious Programmer
Curious Programmer

Reputation: 127

Magento: Get country that user has chosen

I have a piece of code which creates dropdown list of the countries

<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>

I can't figure out how to get the country which user has chosen. Can you please help me?

Upvotes: 1

Views: 1253

Answers (1)

Pragnesh Chauhan
Pragnesh Chauhan

Reputation: 8476

<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);
}  ​

Upvotes: 1

Related Questions