On a product list page of our store, we have (customer-facing) the ability to allow someone to select their Sort By in a dropdown box, one of the options being "A to Z." Due to some constraints on our backend, we have no way of "forcing" the page to sort "A to Z," instead only sorting on "Most Popular" and a few other options.

The issue is that we do want this particular page to sort A to Z by default, and we want it to do so in a way that doesn't interfere with the guest. So, the script would have to trigger before the page loads, select the A to Z sort from that drop down box, and then fire the page reload (or reload the page as soon as possible, so a customer doesn't see the page "double load" or anything). Make sense?

I have no idea how to start with this javascript, but one solution is to hide the content of the page via CSS, then fire the dosort using some kind of script, but there may be something way more elegant than that...

I've stumbled on this at Daft Logic and the last bit of code (Post-Render Selection by Value) seems to do something similar to what I want.

As I haven't tested yet in a live environment, I'm worried that it will select the value I want in the dropdown box (sortProductsAtoZ) but not actually fire the doSort in the dropdown menu...

neuronphaser
—
2012-08-01T22:00:52Z —
#3

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