views:

751

answers:

1

Is there any way to remove the submitHandler or invalidHandler once they are set? If I submit my form and cancel out of my confirmation modal window, my other buttons are inheriting those handlers and not doing what they are suppose to do.

I've tried unbinding the form submit at various places. As well as trying to redefine the validation for the back and save buttons but it's like the submitHandler is always called first

<script type="text/javascript">


    $(document).ready(function() {


        $(window).keydown(function(event){

             document.getElementById('save').src = "/bttn-save.jpg";

        });


        $.validator.setDefaults({
             submitHandler: function() { 
                  tb_show("", "#TB_inline?height=400&width=600&inlineId=confirmblock", null);
             }
        });

        var errorimage = "<img src=\"error.png\" width=\"19\" height=\"19\" alt=\"error\" title=\"error\" style=\"vertical-align:top;margin-top:5px;\" />";

        $('#submit').click(function(e) {

            $('#promoForm').validate({
                submitHandler: function() { 
                  tb_show("", "#TB_inline?height=400&width=600&inlineId=confirmblock", null);
             },
                invalidHandler: function(e, validator) {
                 var errors = validator.numberOfInvalids();
   if (errors) {
        tb_show("", "#TB_inline?height=150&width=250&inlineId=errorblock", null);
   }  

     },
                errorElement: "span",
                rules: {
                    additionalinfo: "required"
                },
                messages: {
                    additionalinfo: errorimage
                } 

            });

            document.getElementById('td_info').innerHTML = document.getElementById('additionalinfo').value;

        });

        $('#back').click(function() {
            $("#promoForm").attr("action", "/step6/?action=back&email=%%=RequestParameter("email")=%%"); 
        });


        $('#save').click(function() {
            $("#promoForm").attr("action", "/step7/?action=save&email=%%=RequestParameter("email")=%%"); 
        });

        $('#confirm').click(function() {
            document.getElementById('promoForm').action = "http://pages.email.microsoftemail.com/thatsit/?email=%%=RequestParameter("email")=%%"
            document.getElementById('promoForm').submit(); 

        });

        $('#attach').click(function() {
            tb_show("", "#TB_inline?height=300&width=336&inlineId=uploadblock", null);
        });

    });
</script>
A: 

When they exist the modal, I remove all events from the form. When I click on my submit button, I add all my validation back on. This required modifying the ThickBox and Validation JS for my specific case.

Jonathan