Today I was presented with a task on an existing website using the DotNetNuke publishing platform. The customer has created a form using a module in the framework. The form is used to order some stuff and the visitor has to click a number of check boxes depending on what they want to order. There is also ha a bunch of pages with information about the products. Each page has a direct link on i to get to the order page. Now, if the visitor clicks this link the check box for that particular product should be checked, just to make thing easier.
I have no intention on going in to the framework to change the behaviour of the module so I thought I'd try some jQuery on this.
First off the only thing I really know is that the order form will have a header like this "<h1>Order form</h1>" (potentially the module can exist on multiple pages, even multiple times on the same page) and that the product page will have the product name in the url, which is also the text of the check box.
My idea was that first check if the order form exist on the page by looking for the header then check the referrer url and compare this to the check box names. This is the code:
// Automatically set checkboxes if the visitor previously viewed
// a page named the same as the checkbox
// The text element is always a sibling directly following the checkbox
var checkboxName = $(this).next().text();
// DNN url replaces characters in PageName
checkboxName = checkboxName.replace(" ", "").replace("-", "");
if(document.referrer.indexOf(checkboxName) != -1)
Pretty slick right?
Post a Comment