Recently I participated in a code camp at Al-Makinah where we introduce participants to the fundamentals of the front-end component of the web. I was asked to review the model answer to one of the exercises given to the students. It was simple; they take a web page written in HTML, CSS and JavaScript and improve it in a way that shows what they’ve learnt that reflects what they were taught. The exercise addressed several aspects like user experience improvement, semantics, validation of the markup … etc. It was a simple shopping cart with several products cards laid out in a grid.
I spend a lot of time writing HTML. It’s been a part of what I am doing every day for more than a decade. For me, HTML is more than just a few elements that you throw here and there; I invest a lot in picking the elements that I use. While I was reviewing the exercise, I stopped in front of the “Add to Cart” button. It was an <a> tag with a link. I started questioning myself; part of me hates the fact that this is a link not a button inside a form. It makes perfect sense to be a button. Of course it can be made anything. Simply attaching a listener that fires an ajax request updating the cart will work. But it doesn’t feel right. This isn’t semantically correct. Before I decide what the “Add to Cart” element should be, I decided I should write down the criteria addressing how this element should behave given all the possible circumstances.
Criteria:
- It must have the same behavior in presence or absence of JavaScript.
- If there are other fields like “amount,” pressing enter (submitting the form) should behave like clicking the button.
At this point I was convinced that this should be a submit button not a link. I quickly realized that this will require each product card to have a form tag with more elements like hidden input with product id for example. In big shops, the home page sometimes hosts a lot of product cards. It even uses sliders to save the space for “Newly arrived,” “Hot offers,” “Hot in category X” and the list can go on. A single page can contain more than a hundred of product cards. All this increase the amount of the HTML tags we serve to the user and increase the page size (comparing to serving a single <a> tag per card).
There is also another problem the submit button doesn’t address and it is very common. It’s the products that need you to select attributes before adding it to your cart (like shirt size or color). It’s common that these product cards redirect the user to the full details page of the product asking him to pick the required attributes in order to add the proper item to the cart. Now I changed my mind; I don’t think it’s a problem using a link for this functionality. I decided to change the first rule I mentioned earlier; it shouldn’t have the same behavior. It just should work in a way.
Before discussing the possible scenarios, I want to clarify something before getting into the argument of whether we should support users with no JavaScript or not. I believe both sides of the argument have valid points; however, there are reasons that you don’t want to lose even the smallest fraction of the users without JavaScript. We’re talking about e-commerce where conversion is translated directly into money. The solution is also pretty simple whether you decided to go with progressive enhancement or graceful degradation as you will see later on.
The available scenarios
Using button
If the product can be added directly to the cart, use button inside a form tag. It can use ajax when JavaScript is available or submit to the server directly when it isn’t (embracing progressive enhancement).
Pros:
- Semantically, it is more accurate.
- The behavior is similar in presence or absence of JavaScript.
Cons:
- Require more code for form tag and other elements that identify the product.
If the product cannot be added without selecting attributes, use an anchor tag linking to the full product details page.
Using link
Use links in all cases. When JavaScript is available, hijack the click event and add the product to the cart using ajax (embracing graceful degradation). If it isn’t, direct the user to the full details page.
Pros:
- Requires less HTML, just a link with data attribute for product id.
Cons:
- The experience is different based on the presence or absence of JavaScript.
- In absence of JavaScript, the link that says “Add to Cart” will do something completely different. It should then say “Show product details.” This might cause confusion for people using assistive technologies like screen readers.
How other e-commerce platforms address this issue?
I decided to review how the other popular e-commerce platforms address this issue. At robusta, we have success stories building successful big e-commerce platforms in Egypt using popular platforms like WooCommerce and Magento Enterprise Edition. I picked the popular open source e-commerce platforms available which provided a demo and a default theme. Now, bear in mind that the result of this analysis is highly based on the used theme. If you are using a different theme it is very likely that your theme uses a different markup than what I am about to show you. The default theme is important because developers use it as a boilerplate for their themes. Some platforms like Magento allow defining a parent theme and extend it to override some of its parts instead of writing everything from scratch.
Magento 2
Magento comes with a theme called Luma. It uses a button tag without a form. The button itself has some additional data attributes related to the product. As you might guess, this implementation doesn’t work except when JavaScript is available. It’s worth mentioning that Magento 2 utilizes RequireJS to split JavaScript into modules. Luma theme by default loads 119 JavaScript file in the homepage alone. With Magento, JavaScript bundler merely seems to function properly; there is a big chance for failure at any point (by network timeout, server failure, slow internet connection,…etc.). It’s disappointing to see the e-commerce giant uses an inaccessible solution that only works with JavaScript.
WooCommerce
The number 1 WordPress plugin for e-commerce really shines with its implementation. It uses a link that directs to the current page with the query string “?add-to-cart=id”. When JavaScript is available, the product is added to the cart using ajax. When it’s absent, WooCommerce handles it in a way different than the scenarios I mentioned before. The product is added to the cart and the user is redirected to the same page again with a success message on top. WooCommerce says “Add to cart” and it delivers what it says exactly with no confusion. When the product requires picking attributes, it redirects the user to the product details page.
OpenCart
OpenCart uses a button without a form that has an onclick attribute. It requires JavaScript to work. When JavaScript is available the product is added to the cart. If the product requires selection of attribute the same button redirects the user to the full details page.
VirtueMart
Perhaps this is one of the least known e-commerce platforms but it is well known across Joomla community. VirtueMart uses a classic form with a button. If JavaScript is available, the experience is enhanced with ajax. If not, the form is submitted and the user is redirected to the cart page. If the product requires selection of additional attributes the button is disabled and the options are displayed to pick from inside the cart. VirtueMart embraces progressive enhancement and provides a solution that works smoothly.
osCommerce
This is an obligatory mention to the e-commerce dinosaur. From the minute you check the demo you get the feeling that you stepped back in time into PhpNuke. osCommerce doesn’t include an add to cart button in the listing. Adding the product to the cart is only available inside the full product details.
Conclusion
There are several methods to mark down the “Add to Cart” button. We should always embrace a method that guarantees the button will work then improve the experience using JavaScript.
Nicely put. Thanks a lot!
what does viagra cost in canada viagra cialis levitra href page
generic viagra online
using viagra in women – https://genericviagrarcp.com
KeithKax
RichardNup
ErnestoByday
With thanks! Numerous content!
viagra alternative review k b viagra uden recept
viagra generic
viagra and birth control – https://genericviagrantx.com
KeithKax
RichardNup
ErnestoByday
Nicely put, Regards!
email viagra genic viagra from india
viagra for sale uk
viagra 999 – https://genericviagrantx.com
KeithKax
RichardNup
ErnestoByday
You actually expressed it adequately.
viagra lawsuits how to safely buy viagra online
viagra for women
eyesight viagra – https://genericviagramsl.com
KeithKax
RichardNup
ErnestoByday
You mentioned it effectively!
canada viagra buy cvs generic viagra
viagra for sale uk
nude viagra video – https://genericviagrantx.com
KeithKax
RichardNup
ErnestoByday
Point well used..
honolulu viagra use of viagra
viagra pills
how viagra enhances sex – https://genericviagramsl.com
KeithKax
RichardNup
ErnestoByday
Truly quite a lot of helpful information!
viagra half price viagra head office toronto
viagra pills
viagra board – https://genericviagrantx.com
KeithKax
RichardNup
ErnestoByday
Awesome information. Appreciate it.
g postmessage viagra guest remember my viagra pornstar
buy viagra
viagra talk – https://genericviagrantx.com
KeithKax
RichardNup
ErnestoByday
Really tons of valuable information!
viagra pulmonary hypertension viagra and gay wrestling
viagra generic
mapuche viagra – https://genericviagramsl.com
KeithKax
RichardNup
ErnestoByday
Fantastic material. Appreciate it!
generic levitra celias viagra amyl nitrate erection viagra
viagra pills
china viagra – https://genericviagrarcp.com
KeithKax
RichardNup
ErnestoByday
Thank you, An abundance of forum posts.
best rated generic viagra online stores genuine viagra online without prescription
viagra online
viagra canada satisfaction guarantee – https://genericviagrantx.com
KeithKax
RichardNup
ErnestoByday
You actually mentioned it wonderfully!
viagra and drug interactions viagra rht
generic viagra 100mg
limbaugh rush dominican republic viagra – https://genericviagramsl.com
KeithKax
RichardNup
ErnestoByday
Nicely put, Thanks.
ntg interaction with viagra joke viagra ads
viagra without a doctor prescription
online prescription viagra – https://genericviagrarcp.com
KeithKax
RichardNup
ErnestoByday
You’ve made your point.
viagra come funziona cheap genaric viagra kamagra
viagra online
customer reviews for viagra – https://genericviagramsl.com
KeithKax
RichardNup
ErnestoByday
You actually said it fantastically!
irish viagra viagra superstore
viagra online
hypertension viagra – https://genericviagrantx.com
KeithKax
RichardNup
ErnestoByday
Nicely put. Cheers.
can i drink and take viagra cheap generic viagra substitutes
viagra for sale uk
subaction showcomments viagra archive older – https://genericviagramsl.com
KeithKax
RichardNup
ErnestoByday
Factor certainly applied.!
alcohol with viagra what to expect from viagra
viagra for sale uk
cheapest viagra substitut – https://genericviagramsl.com
KeithKax
RichardNup
ErnestoByday
You made the point.
viagra cialis levetra cialis viagra softabs
buy viagra
g postmessage viagra guest post – https://genericviagrantx.com
KeithKax
RichardNup
ErnestoByday
Thank you, Useful stuff.
viagra cost walgreens viagra 32
viagra pills
boots viagra uk – https://genericviagrarcp.com
KeithKax
RichardNup
ErnestoByday
Very good info, Thanks!
pure theatrical viagra 3 caverta veega generic viagra
viagra for sale uk
viagra add men singing – https://genericviagrantx.com
KeithKax
RichardNup
ErnestoByday
Awesome information. With thanks!
active ingredient of viagra online pharmacy viagra accepts paypal
viagra online
viagra availability – https://genericviagrarcp.com
KeithKax
RichardNup
ErnestoByday
Excellent information. Cheers.
viagra or levitra which is better can viagra be taken with norvasc
viagra without a doctors prescription
new forms of viagra – https://genericviagramsl.com
KeithKax
RichardNup
ErnestoByday
Truly many of superb tips!
viagra examples viagra sellers cialis levitra
viagra pills
generic viagra sold on line – https://genericviagrantx.com
KeithKax
RichardNup
ErnestoByday
Good write ups. Cheers.
viagra pills without a prescription how will viagra feel
viagra without a doctors prescription
viagra for sale in eastbay california – https://genericviagrarcp.com
KeithKax
RichardNup
ErnestoByday
Many thanks, Very good information!
health shop port louis generic viagra what happens when teens take viagra
viagra pills
cheap generic kamagra kamagra uk viagra – https://genericviagramsl.com
KeithKax
RichardNup
ErnestoByday
Seriously quite a lot of superb information!
dr fox viagra apteekki viagra
generic viagra
genuine viagra in australia – https://genericviagrarcp.com
KeithKax
RichardNup
ErnestoByday
Position certainly considered.!
a penis on viagra female viagra pharmaceutical
viagra without a doctors prescription
across the border viagra – https://genericviagramsl.com
KeithKax
RichardNup
ErnestoByday
Thanks a lot, Helpful stuff.
viagra official web site cialis cialis cialis genuinerx net viagra
viagra for women
publicidad viagra marketing – https://genericviagrantx.com
KeithKax
RichardNup
ErnestoByday
Cheers! An abundance of advice.
how is viagra used for women best retail pharmacy viagra price
viagra generic
viagra boring edinburgh pages spam boring – https://genericviagramsl.com
KeithKax
RichardNup
ErnestoByday
Amazing material. Cheers!
viagra super active viagra online insurance
viagra without a doctor prescription
viagra paxil – https://genericviagrantx.com
KeithKax
RichardNup
ErnestoByday
You actually stated that well.
viagra without prescription cipla viagra half price pharmacy
viagra for women
alternatives to viagra – https://genericviagramsl.com
KeithKax
RichardNup
ErnestoByday
You explained it exceptionally well.
viagra cialis levitra smaple pack viagra unsuccessful entry
viagra online
viagra online order viagra – https://genericviagramsl.com
KeithKax
RichardNup
ErnestoByday
Nicely put. Kudos!
discount generic viagra panama viagra with delayed ejaculation
generic viagra
purchasing viagra – https://genericviagramsl.com
KeithKax
RichardNup
ErnestoByday
With thanks. Ample content.
viagra next day supplier viagra
generic viagra 100mg
best viagra buy – https://genericviagrantx.com
KeithKax
RichardNup
ErnestoByday
Kudos. Excellent information!
is viagra prescription in canada men with erectile dysfunction l-arginine viagra
viagra without a doctors prescription
funny picture viagra – https://genericviagramsl.com
KeithKax
RichardNup
ErnestoByday
Great material. Thanks a lot.
xtabentun mexican viagra cialis viagra or levitra best
generic viagra 100mg
viagra side-effects – https://genericviagrantx.com
KeithKax
RichardNup
ErnestoByday
You reported that well!
viagra brasil how effective is viagra
cheap viagra
why are kids using viagra – https://genericviagrantx.com
KeithKax
RichardNup
ErnestoByday
You definitely made the point.
viagra business increasing dosage of viagra
viagra 100mg
viagra y cialis espa ol – https://genericviagrarcp.com
KeithKax
RichardNup
ErnestoByday
You revealed that adequately.
natual viagra stop viagra flushing
buy viagra online
viagra in south africa – https://genericviagramsl.com
KeithKax
RichardNup
ErnestoByday
You made your point.
viagra insurance coverage who manufactures viagra
buy viagra
dosages of viagra – https://genericviagramsl.com
KeithKax
RichardNup
ErnestoByday
Awesome data, With thanks!
if viagra doesnt work what next tiger woods viagra
buy generic viagra
viagra cheap express – https://genericviagramsl.com
KeithKax
RichardNup
ErnestoByday
Cheers! Fantastic stuff!
does viagra expire buying viagra online vs doctor prescription
viagra online
boys viagra – https://genericviagrarcp.com
KeithKax
RichardNup
ErnestoByday
You stated that wonderfully.
viagra relaxes spinkter generica viagra
viagra online
will viagra improve ed over time – https://genericviagramsl.com
KeithKax
RichardNup
ErnestoByday
You explained that superbly!
the female viagra hits the nhs viagra marketing tools
viagra online
where do you buy viagra online – https://genericviagrarcp.com
KeithKax
RichardNup
ErnestoByday
Excellent forum posts. Regards.
viagra by post viagra buy germany
viagra 100mg
cheap kamagra uk viagra – https://genericviagrarcp.com
KeithKax
RichardNup
ErnestoByday
Thank you, Numerous tips!
viagra and young adults kamagra viagra sildenafil site
viagra 100mg
viagra softtabs overnight – https://genericviagrantx.com
KeithKax
RichardNup
ErnestoByday
You mentioned it adequately.
viagra rules buy viagra online inurl
viagra without a doctors prescription
find viagra edinburgh sites pages posted – https://genericviagrantx.com
KeithKax
RichardNup
ErnestoByday
Position certainly regarded!.
next day viagra viagra forum
cheap viagra
an effective natural alternative to viagra – https://genericviagrantx.com
KeithKax
RichardNup
ErnestoByday
Cheers! Awesome information!
best pharmacy viagra price cheap viagra no prescription overnight
buy viagra online
cumparare viagra – https://genericviagramsl.com
KeithKax
RichardNup
ErnestoByday
Really lots of superb tips.
viagra ejactulation i need viagra today
viagra without a doctors prescription
wedding viagra – https://genericviagramsl.com
KeithKax
RichardNup
ErnestoByday
You said it perfectly.!
mccain avoids viagra cnn does viagra negatively effect orgasm
viagra 100mg
will viagra go generic soon – https://genericviagramsl.com
KeithKax
RichardNup
ErnestoByday
Incredible plenty of awesome material!
viagra amsterdam for sale viagra
viagra pills
3generic meltabs viagra – https://genericviagrarcp.com
KeithKax
RichardNup
ErnestoByday