Welcome to WebmasterWorld Guest from 54.226.246.160

Forum Moderators: open

Message Too Old, No Replies

Any issues with Javascript in Submit Buttons?

     

kjs50

12:58 am on Sep 22, 2008 (gmt 0)

10+ Year Member



Hello,

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!

vincevincevince

1:08 am on Sep 22, 2008 (gmt 0)

WebmasterWorld Senior Member vincevincevince is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Javascript validation is useful because it offers an immediate response; however this should never be relied upon by your system as it is far too easy to bypass.

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.

kjs50

1:56 am on Sep 22, 2008 (gmt 0)

10+ Year Member



Thanks for the reply. I'm not as concerned about the validation portion of it, but more of the user not being able to add it to the cart because of the javascript.

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.

lavazza

2:39 am on Sep 22, 2008 (gmt 0)

5+ Year Member



is it safe to assume that everyone has javascript enabled nowadays
I 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

vincevincevince

4:09 am on Sep 22, 2008 (gmt 0)

WebmasterWorld Senior Member vincevincevince is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Typically; Javascript should not block the ability of the user to use the system. Here's an example of what I consider to be a way to use it that degrades reasonably well:

<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.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month