Forum Moderators: open
I am looking into Magento shopping cart, but it has javascript for validation in every Add to Cart button. Seems like this is a potential issue. Having trouble figuring out what percentage of users don't have javascript enabled.
Any advice would be appreciated from people using javascript validation.
Thanks!
To test your particular code, disable javascript and then try to submit an incorrectly completed form. The server side software (e.g. PHP) should catch the error and inform you even though Javascript missed it.
I am not sure what Magento does in this regard; do feel free to post back your results.
If the user has javascript disabled, they won't be able to add it to their cart. But just not sure what % of users this would apply to. Or is it safe to assume that everyone has javascript enabled nowadays.
Thanks.
is it safe to assume that everyone has javascript enabled nowadaysI don't have any stats to hand, but my guess is 'to the contrary, more and more'; given how many times the NoScript extension for Firefox has been downloaded AND how often I read that WebTV, mobile phones, and PDAs have limited support for JavaScript
<form method="POST" action="addtocart">
<input type="text" name="quantity" value="1">
<input type="hidden" name="product" value="widget">
<input type="submit" onClick="javascript:return validation()" value="Add To Cart">
</form> The function 'validation()' should return 'true' on success; and 'false' on failure (along with visual feedback about the problem).
When a user with Javascript clicks the submit button, the function 'validation()' is executed. Only when 'true' is returned does the form then submit.
When a user without Javascript clicks the submit button, the onClick does nothing (is ignored). The browser proceeds to submit the form. Server side code (Perl, PHP, ASP, etc.) will then detect if there's something wrong with the entry.