Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't this javascript redirecting?

I want to have the user click on a button and redirect him/her to a different site I have used the window.location before but for some reason it's not working this time. I'm sure the selector is correct as if I change window.location to alert it alerts every time, so I can't figure what I'm doing wrong.

$('#show').click(function(){
        if($('select[name="customers"]').val() == '')
            window.location.replace = 'http://google.com/';
    });
like image 788
Tsundoku Avatar asked Feb 23 '26 21:02

Tsundoku


1 Answers

You have to use either

window.location.replace("http://google.com"); // This is like http redirect

or

window.location.href = "http://google.com"; // This is like a link

You can't do window.location.replace= "http://google.com";

like image 195
viper Avatar answered Feb 25 '26 10:02

viper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!