views:

14

answers:

2

i am trying to setup a simple javascript form. User must enter correct discount code. If not they get an error message. if correct, they are directed to another website. any help would be greatly appreciated!

+1  A: 

This kind of verification should be done server side, not client side (hence not in javascript) for security reasons.

If you still want do this verification, then look for AJAX methods.


Resources :

Colin Hebert
A: 

This could be done on submit using jQuery. For example $(selector).load("/ValidateCode.php?code='"+$("#code").val()+"'"); (or something similar).

However the actual validation would be in the server-side validation page. The reason being that you would have to validate the code against all other codes - so to do this in pure jQuery you would have to have all codes somewhere in the source code so users could simply use the source code to obtain a valid code.

So the answer is: yes you could validate the code in JS / jQuery, but it is best to validate in a server-side page which is loaded by JS / jQuery - thus the application is still secure and the page still appears seamless (i.e. it does not refresh). The validation page could just output an image of a tick or cross or something, which you load into a span next to the code entry box.

Hope this helps.

ClarkeyBoy