Opencart and support for javascript disabled

I realised recently that my Opencart installation does not allow users to checkout if they have javascript disabled. It’s a little unfortunate because there’s no warning of this at all to the user – you can fill your basket OK, and then you’re stuck. This is a shame since otherwise I like Opencart, it’s pretty easy to configure once you’ve got the hang of its MVC architecture. These threads on the Opencart forum make it look like this isn’t likely to change.

Now, not many people are going to have their js disabled, but do we really want to disenfranchise the few, or even one, that do/does? I think not.

There are two situations where Opencart uses javascript on navigation. The first is for a simple link:

<a onclick="location = '<?php echo str_replace('&', '&', $back); ?>'" class="button">

This is simply fixed by making this:

<a href="<?php echo str_replace('&', '&', $back); ?>" class="button">

The other situation is slightly more complex and happens where forms need to be submitted. As a default Opencart has, for example:

<a onclick="$('#payment').submit();" class="button"><span><?php echo $button_continue; ?></span></a>

The quick and dirty solution is to replace this link with a “normal” input tag of type submit. However, these are more difficult to style. Conseqeuntly, I’ve amended the html to:

<span class="button hide_js"><input class="hide_js" type="submit" value="<?php echo $button_continue; ?>"/></span>
<a onclick="$('#payment').submit();" class="button show_js"><span><?php echo $button_continue; ?></span></a>

with some simple jQuery, which I’ve added to ajax_add.js:

	$('.hide_js').hide();
	$('.show_js').show(); 

and this css

show_js{display:none}

So, for a user without javascript, the link which relies on javascript is hidden by the css and a simple input button is used instead. For a user with javascript enabled, on page load the input button is hidden and the javascript link displayed. Using OC 1.4.9.5 I found one situation where the form does not extend to include the div which contains the button – I just extended it so it did.

With a bit of judicious css, the “non javascript” buttons can be virtually identical (not pixel perfect) to the javascript ones – that’s why I’ve wrapped the inputs in the span as shown above, and then extending the styling used for .button span to include .button input.

Update 23 February: I subsequently spotted another issue with javascript disabled which is that it’s impossible to select the zone in an address since this is populated only by javascript. Fixing this is slightly more complex – see this post.

Tags:

Useful? Interesting? Leave me a comment

I've yet to find a way of allowing code snippets to be pasted into Wordpress comments - so if you're trying to do this you'd be better off using the contact form.