Welcome to WebmasterWorld Guest from 54.160.254.203

Forum Moderators: open

Message Too Old, No Replies

Any issues with Javascript in Submit Buttons?

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

Junior Member

10+ Year Member

joined:Oct 8, 2002
posts: 150
votes: 0


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!

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

Senior Member from MY 

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

joined:Apr 1, 2003
posts:4847
votes: 0


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.

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

Junior Member

10+ Year Member

joined:Oct 8, 2002
posts:150
votes: 0


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.

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

Preferred Member

5+ Year Member

joined:May 29, 2007
posts: 578
votes: 0


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
4:09 am on Sept 22, 2008 (gmt 0)

Senior Member from MY 

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

joined:Apr 1, 2003
posts:4847
votes: 0


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.

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members