Search code examples
javascriptcontact-form-7

Redirect contact form 7 with javascript


I do not want to use the additional setting because its filled with a bunch of analytics code. I want to my javascript function to fire when the button is clicked. example the contact form 7's button ID is #aircraft_submit. I have tried the following

 <script type="text/javascript">
    jQuery( document ).ready(function() {
        jQuery('').click(function(){
            document.getElementById("#aircraft_submit").onclick = function(){
                window.location.replace("http://stackoverflow.com");
            }
        });
    }
</script>

I think I might be understanding contact form 7 incorrectly. Please note I do not want to use additional option in contact form 7 at all.


Solution

  • Seen as you are using jquery anyway, you can add the click on the submit button like this

    jQuery( document ).ready(function() {
        jQuery("#aircraft_submit").on('click', function(e){
            e.preventDefault();
            window.location.href  = "http://stackoverflow.com";
        });
    }
    

    You'll need to prevent the default 'submit' action