{"id":2108,"date":"2012-02-15T11:47:07","date_gmt":"2012-02-15T11:47:07","guid":{"rendered":"http:\/\/www.simonbattersby.com\/blog\/?p=2108"},"modified":"2012-02-23T10:58:40","modified_gmt":"2012-02-23T10:58:40","slug":"opencart-and-support-for-javascript-disabled","status":"publish","type":"post","link":"https:\/\/www.simonbattersby.com\/blog\/2012\/02\/opencart-and-support-for-javascript-disabled\/","title":{"rendered":"Opencart and support for javascript disabled"},"content":{"rendered":"<p>I realised recently that my <a href=\"http:\/\/www.adelaidewalker.co.uk\">Opencart installation<\/a> does not allow users to checkout if they have javascript disabled. It&#8217;s a little unfortunate because there&#8217;s no warning of this at all to the user &#8211; you can fill your basket OK, and then you&#8217;re stuck. This is a shame since otherwise I like Opencart, it&#8217;s pretty easy to configure once you&#8217;ve got the hang of its MVC architecture. <a href=\"http:\/\/forum.opencart.com\/viewtopic.php?t=33416&#038;p=162817\">These<\/a> <a href=\"http:\/\/forum.opencart.com\/viewtopic.php?f=20&#038;t=49057\">threads<\/a> on the Opencart forum make it look like this isn&#8217;t likely to change.<\/p>\r\n\r\n<p>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.<\/p>\r\n\r\n<p>There are two situations where Opencart uses javascript on navigation. The first is for a simple link:<\/p>\r\n\r\n<pre>&lt;a onclick=\"location = '&lt;?php echo str_replace('&#038;', '&amp;', $back); ?&gt;'\" class=\"button\"&gt;<\/pre>\r\n\r\n<p>This is simply fixed by making this:<\/p>\r\n\r\n<pre>&lt;a href=\"&lt;?php echo str_replace('&#038;', '&amp;', $back); ?&gt;\" class=\"button\"&gt;<\/pre>\r\n\r\n<p>The other situation is slightly more complex and happens where forms need to be submitted. As a default Opencart has, for example:<\/p>\r\n\r\n<pre>&lt;a onclick=\"$('#payment').submit();\" class=\"button\"&gt;&lt;span&gt;&lt;?php echo $button_continue; ?&gt;&lt;\/span&gt;&lt;\/a&gt;<\/pre>\r\n\r\n<p>The quick and dirty solution is to replace this link with a &#8220;normal&#8221; <code>input<\/code> tag of type <code>submit<\/code>. However, these are more difficult to style. Conseqeuntly, I&#8217;ve amended the html to:<\/p>\r\n\r\n<pre>&lt;span class=\"button hide_js\"&gt;&lt;input class=\"hide_js\" type=\"submit\" value=\"&lt;?php echo $button_continue; ?&gt;\"\/&gt;&lt;\/span&gt;\r\n&lt;a onclick=\"$('#payment').submit();\" class=\"button show_js\"&gt;&lt;span&gt;&lt;?php echo $button_continue; ?&gt;&lt;\/span&gt;&lt;\/a&gt;<\/pre>\r\n\r\n<p>with some simple jQuery, which I&#8217;ve added to ajax_add.js:<\/p>\r\n\r\n<pre>\t$('.hide_js').hide();\r\n\t$('.show_js').show(); <\/pre>\r\n\r\n<p>and this css<\/p>\r\n\r\n<pre>show_js{display:none}<\/pre>\r\n\r\n<p>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 &#8211; I just extended it so it did.<\/p>\r\n\r\n<p>With a bit of judicious css, the &#8220;non javascript&#8221; buttons can be virtually identical (not pixel perfect) to the javascript ones &#8211; that&#8217;s why I&#8217;ve wrapped the inputs in the span as shown above, and then extending the styling used for <code>.button span<\/code> to include <code>.button input<\/code>.<\/p>\r\n\r\n<p><strong>Update 23 February:<\/strong> I subsequently spotted another issue with javascript disabled which is that it&#8217;s impossible to select the zone in an address since this is populated only by javascript. Fixing this is slightly more complex &#8211; see <a href=\"\/blog\/2012\/02\/creating-a-mobile-version-of-an-opencart-shop-5\/\">this post<\/a>.<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>I realised recently that my Opencart installation does not allow users to checkout if they have javascript disabled. It&#8217;s a little unfortunate because there&#8217;s no warning of this at all to the user &#8211; you can fill your basket OK, and then you&#8217;re stuck. This is a shame since otherwise I like Opencart, it&#8217;s pretty [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[28],"class_list":["post-2108","post","type-post","status-publish","format-standard","hentry","category-web-design-and-build","tag-opencart"],"_links":{"self":[{"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/posts\/2108","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/comments?post=2108"}],"version-history":[{"count":0,"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/posts\/2108\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/media?parent=2108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/categories?post=2108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/tags?post=2108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}