Hi there, A few things to consider..
>From your HTML form code: change this: <input type="checkbox" name="attributes[accept-t-and-c]" id="accept-t- and-c" value="yes" CHECKED /> to: <input type="checkbox" name="attributes[accept-t-and-c]" id="accept-t- and-c" value="yes" checked="checked" /> >From you JS Code: Change the following: $("input[checkout]") to read: $("input[name=checkout]"); // you are matching attribute 'name' with value 'checkout' Regarding checking checkbox is checked or not use..change: if ($("#accept-t-and-c").attr("checked") !== true) To: if( $("#accept-t-and-c").is(':checked') == false ). Ref: http://docs.jquery.com/Traversing/is Also.. after showing the alert box, you have return false, otherwise the form just get submitted. after this line... alert("You have to agree to our terms and conditions to make a purchase!"); Add this: return false; I hope it helps, Thanks, Abdullah. On Apr 3, 3:16 am, osu <onesiz...@googlemail.com> wrote: > Hi, > > I'm trying to validate a checkbox before going to checkout in a shop > (without using the validate plugin), but the JQuery doesn't seem to be > working at all (i.e. nothing happens). Tried debugging in Firebug, but > I can't seem to pinpoint the problem. > > Can someone have a look and see what I'm doing wrong please? > > Thanks, > > osu > > HTML: > > <form action="/cart" method="post" id="cartform"> > <input type="submit" id="update-cart" name="update" value="Update > basket" class="checkout-btns" /> > <input type="submit" value="Checkout" name="checkout" class="checkout- > btns" /> > <a href="/" class="checkout-btns" />Continue shopping</a> > <p id="tandc"> > <input type="checkbox" name="attributes[accept-t-and-c]" id="accept-t- > and-c" value="yes" CHECKED /> > <label for="accept-t-and-c">Please confirm you have read and > understood our <a href="#">Terms and Conditions</a> (required)</label> > </p> > </form> > > JQUERY: > > <script type="text/javascript"> > //<![CDATA[ > // JQuery function to test if t-and-c checkbox checked > $(document).ready(function(){ > $("input[checkout]").click(function(){ > var pass = false; > if ($("#accept-t-and-c").attr("checked") !== > true){ > alert("You have to agree to our terms > and conditions to make a > purchase!"); > } else > // let 'em through to checkout > pass = true; > }); > }); > //]]> > </script>