user1048676
user1048676

Reputation: 10066

jQuery page redirect not working on button click

All, I've got the following code:

var site_url = 'http://localhost/website/';
jQuery("#cancel_song_choice").click(function(event){
    cancel_url = site_url + "event-form";
    window.location.href(cancel_url);
});

Then I have the following HTML:

<button id="cancel_song_choice">Cancel Search</button>

When I click on the button it just keeps redirecting me back to the page that I'm on instead of going to the cancel url that I specified. I alert the cancel_url and it shows me the right one. Any ideas what I'm doing wrong?

Upvotes: 1

Views: 5965

Answers (2)

Mike
Mike

Reputation: 781

window.location.href=cancel_url;

should work

Upvotes: 0

James Hill
James Hill

Reputation: 61793

href is not a function, it's a property. Use: window.location.href = cancel_url;:

var site_url = 'http://localhost/website/';
jQuery("#cancel_song_choice").click(function(event){
    window.location.href = site_url + "event-form";
});

Check out window.location on MDN.

Upvotes: 4

Related Questions