Here's my new code. Problem is, I'm still not able to fire the doSort from the dropdown box, so while the page loads and then the correct entry in the box is selected, the page doesn't actually re-sort the products.
Note that -- by necessity -- my javascript has to come before the Sort By dropdown on the page, which is part of the reason I'm doing all these onload calls in order to wait for everything to be done loading.
JavaScript: this code is meant to
1. Wait till everything's loaded on the page.
2. Select sortProductsAToZ in the dropdown.
3. Fire the doSort of the dropdown box so the products actually sort A-Z.
Code:
<script>
document.body.onload = function () {
function setSelectedIndex(s, valsearch)
{
// Loop through all the items in drop down list
for (i = 0; i< s.options.length; i++)
{
if (s.options[i].value == valsearch)
{
// Item is found. Set its property and exit
s.options[i].selected = true;
break;
}
}
return;
}
window.document.body.onload = setSelectedIndex(document.getElementById("sortSelection"),"sortProductsAToZ");
dojo.addOnLoad = function() {
doSort(sortProductsAToZ);
};
}
</script>
Sort By (dropdown box)
Code:
<div class="sortProductsMain">
<label class="sortProductsHeader" id="sortById">Sort By: </label>
<select dojoattachevent="onchange: doSort" id="sortSelection">
<option class="sortProductsDefault" value="sortProductsDefault" id="sortProductsDefault">Most Popular</option>
<!--<option id="sortProductsFeatured" value="sortProductsFeatured" class="sortProductsFeatured">Featured</option>-->
<option class="sortProductsHighestRated" value="sortProductsHighestRated" id="sortProductsHighestRated">Highest Rated</option>
<option class="sortProductsNewest" value="sortProductsNewest" id="sortProductsNewest">Newest</option>
<!--<option id="sortProductsMostPopular" value="sortProductsMostPopular" class="sortProductsMostPopular">Most Popular</option>-->
<option class="sortProductsAToZ" value="sortProductsAToZ" id="sortProductsAToZ">A-Z</option>
<option class="sortProductsZToA" value="sortProductsZToA" id="sortProductsZToA">Z-A</option>
<option class="sortProductsPriceHighToLow" value="sortProductsPriceHighToLow" id="sortProductsPriceHighToLow">$$$-$</option>
<option class="sortProductsPriceLowToHigh" value="sortProductsPriceLowToHigh" id="sortProductsPriceLowToHigh">$-$$$</option>
</select>
</div>
In testing, I can get steps 1 and 2 to work, but never step three (firing the doSort). What am I doing wrong?
Bookmarks