0

I have this page:

link

Here on the homepage, you will find a button called "Get a quote". When you click on this button I want to open link "google.com".

I tried to do this with jQuery using this code but it's not working.

 jQuery(document).ready(function($) {
    $('.wpcf7-form-control wpcf7-submit').click(function() {
    window.location = "www.google.com/index.php?id=";
    });
});

This site is made with Wordpress and I used the plugin Contact Form 7

<div class="contact-frm">
        <div class="right">
            <?php echo do_shortcode('[contact-form-7 id="9" title="get a quote"]'); ?>
        </div>
    </div>

Can you please help me to solve this problem?

Thanks in advance!

Alex
  • 8,093
  • 6
  • 49
  • 79
Gigi
  • 29
  • 3

3 Answers3

4

You forgot two things:

  1. Add a http:// in front of the URL.
  2. Change wpcf7-submit to .wpcf7-submit.

Use this way:

jQuery(document).ready(function($) {
    $('.wpcf7-form-control .wpcf7-submit').click(function() {
        window.location = "http://www.google.com/index.php?id=" + $(this).attr("id");
    });
});
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
  • I added this code but do not understand why not go now ... if I click on the button does not change anything – Gigi Jun 15 '15 at 10:50
0

use the below code:

window.location = "http://www.google.com/index.php?id=";

adding http:// before the link can help you.

Also use:

$('.wpcf7-form-control .wpcf7-submit');

if wpcf7-submit is class specify it using dot . in jQuery

if wpcf7-submit is id then specify it using dot # in jQuery

Sourabh Kumar Sharma
  • 2,864
  • 3
  • 25
  • 33
0

Instead of this :

jQuery(document).ready(function($) {
    $('.wpcf7-form-control wpcf7-submit').click(function() {
        window.location = "www.google.com/index.php?id=";
    });
});

Use this :

jQuery(document).ready(function($) {
    jQuery(function($) {
        $(".wpcf7-form-control.wpcf7-submit").click(function() {
            window.location = "http://www.google.com/index.php?id=";
        });
    });
});

It will work for you. There is something you should know:

  • In jquery selector you should write two classas without space
  • $ doesn't work in wordpress, For more information see here
Community
  • 1
  • 1
Hossein Rashno
  • 3,073
  • 1
  • 25
  • 49