+1 for unobtrusive JavaScript.

If you're using jQuery, your form has ID "details" and your checkbox
has the ID attribute "terms" then you could use something like:
$(document).ready(function(){
        $("#details").submit(function(){
                if (!$("#terms").attr("checked")) {
                        $("#terms").addClass("failed-validate")
                        .after('<div class="error">Please confirm that you 
agree to the
terms and conditions</div>');
                };

                //if any inputs on the page have the class 'failed-validate' the
form will not submit
                if ($(":input").hasClass("failed-validate")) {
                        return false;
                } else {
                        return true;
                }
        });

        // remove Terms checkbox error message
        $("#terms").change(function(){  // using change() and not focus()
because it doesn't work in webkit for checkboxes
        $("div.error").remove();
        $(this).removeClass("failed-validate");
});

-- 
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[email protected]

Reply via email to