This is code I took over from a colleague who left:
<input type="text" class="value" placeholder="0"></span><br>
<a href="/model/act/id/'.$model->id.'" class="act act-a" url="/model/act/id/'.$model->id.'">Act Now</a>
<script>
$('.act-a').click(function(){
if(parseInt($('.value').val())>0){
//window.location.href = window.location.origin + $(this).attr('url') + '?r=' + parseInt($('.value').val());
window.location.replace("www.google.com");
return true;
}
return false;
});
</script>
When I click on the link, I never get redirected to http://www.google.com. Originally what I want is to execute the commented code, but setting http://www.google.com to debug, I think to realize that my redirection is being ignored, and instead the original href from the is used!
How can I set window.location.href when a link has been clicked, adding a GET parameter?
return true;tells the browser to do the link’s default action. So, the browser is following the link instead of runningwindow.location.Remove both the return statements, and instead add
e.preventDefault();P.S. You should add
,10toparseIntto make sure the number is parsed as base 10.