when user comes first time in a site it will ask for category subcategory etc..after that i store all value into session then if user come to home page it will show it's working fine for all except subcategory
<?php $tree = $this->helper('techinflo_shop')->getCategoriesDropdown(); ?>
<?php
$categoryvalue = Mage::getSingleton('core/session')->getCategoryValue();
$attributeValue = Mage::getSingleton('core/session')->getAttributeValue();
$homecityvalue = Mage::getSingleton('core/session')->getHomeCityValue();
$subcategoryvalue = Mage::getSingleton('core/session')->getSubCategoryValue();
?>
<script type="text/javascript">
var children = $H(<?php echo json_encode($tree['children']) ?>);
function showCat(obj, level) {
hideContent();
var catId = obj.value;
level += 1;
if ($('cat_container_' + level)) {
$('cat_container_' + level).remove();
}
if (children.get(catId)) {
var options = children.get(catId);
//var html = '<select class="form-control" name="subcategory" required="required" id="cat_' + catId + '" onchange="showCat(this, ' + level + ')">';
var html = '<select class="form-control" name="subcategory" required="required" id="cat_' + catId + '" onchange="showCat()">';
//html += '<option value=""disabled selected> Select </option>';
html += '<option value="' + options[i].entity_id + '"' + (options[i].entity_id == '<?php echo $subcategoryvalue?>') ? ' selected="selected"' : '' + '>' + options[i].name + '</option>';
for (var i = 0; i < options.length; i++) {
html += '<option value="' + options[i].entity_id + '">' + options[i].name + '</option>';
}
html += '</select>';
html = '<div id="cat_container_' + level + '">' + html + '</div>';
$('sub_cat').insert(html);
}
}
//window.onload=showContent();
/*function showContent(){
document.getElementById("default-content").style.display="block";
}
function hideContent(){
document.getElementById("default-content").style.display="none";
}*/
function onLoad()
{
showContent();
showCat(document.getElementById('first_cat'), 2);
}
window.onload=onLoad();
</script>
<form role="form" method="post" action="<?php echo Mage::getUrl('location/index'); ?>" onsubmit="return validation();">
<div class="search_content_area">
<div class="i">
<span> I am a </span>
</div>
<div class="category">
<select id="first_cat" onchange="showCat(this, 2)" class="form-control" required="required" name="parentcate">
<option value="" disabled selected>Select</option>
<?php foreach ($tree['first'] as $cat): ?>
<option value="<?php echo $cat->getUrlKey() ?>" <?php echo ($categoryvalue==$cat->getId())?'selected':'' ?>><?php echo $cat->getName() ?></option>
<?php endforeach ?>
</select>
</div>
<div class="city">
<span> Shopping City </span>
</div>
<div class="select-city">
<select class="form-control" id="mytext1" required="required" name="homecity">
<option value="" disabled selected>Select</option>
<option value="Bangalore" <?php echo ($homecityvalue=='Bangalore')?'selected':'' ?>>Bangalore</option>
<option value="Calcutta" <?php echo ($homecityvalue=='Calcutta')?'selected':'' ?>>Calcutta</option>
<option value="Chennai" <?php echo ($homecityvalue=='Chennai')?'selected':'' ?>>Chennai</option>
</select>
</div>
<div class="look">
<span> Looking For </span>
</div>
<div id="sub_cat"></div>
<div id="default-content">
<div id="cat_container_va">
<select class="form-control" id="mytext">
<option disabled selected>Select</option>
</select>
</div>
</div>
<div class="by">
<span> By </span>
</div>
<div class="brand">
<select class="attribute-brand form-control" id="attribute" required="required" name="attribute">
<option>Select</option>
<?php
$attributes = Mage::getModel('catalogsearch/advanced')->getAttributes();
$attributeArray=array();
foreach($attributes as $a){
if($a->getAttributeCode() == 'brand'){
foreach($a->getSource()->getAllOptions(false) as $option){?>
<option value="<?php echo $option['value'];?>" <?php echo ($attributeValue==$option['value'])?'selected':'' ?>><?php echo $option['label'];?></option>
<?php }
}
}
?>
</select>
</div>
<button class="btn btn-success btn-block let-shop" type="submit">Go</button>
</div>
<div style="clear:both"></div>
</form>