homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Any issues with Javascript in Submit Buttons?

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


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.




 1:08 am on Sep 22, 2008 (gmt 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 Sep 22, 2008 (gmt 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.



 2:39 am on Sep 22, 2008 (gmt 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 Sep 22, 2008 (gmt 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">

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.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved