Someone once called me a geek. At the time I was quite upset, now I'm proud. This is a public access into my thoughts.
Using jQuery to solve problems: automatic checkbox checking
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