I am new in magento development. I try to access all US state and then compare all with one i.e. 'Arizona' if condition is true then it pass its abbreviation to my phtml file.
my phpfunction is:-
public function getAbbr(){
$collection = Mage::getModel('directory/region_api' )->items('US');
foreach($collection as $region){
if($region=='Arizona)
echo 'AZ';
}
}
My jascript code is:-
var abbr=<?php echo $this->getAbbr()?>
But it not works. please any one magento expert give me proper step by step suggestion how i achieve that?
try this, you have missed single quotation mark in 4th line
public function getAbbr(){ $collection = Mage::getModel('directory/region_api' )->items('US'); foreach($collection as $region){ if($region=='Arizona') echo 'AZ'; } }