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 www.google.com. Originally what I want is to execute the commented code, but setting 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. Remove both the return statements, and instead adde.preventDefault();(make sure to change the.clickto$('.act-a').click(function(e){).preventDefaultpreventDefaultjust stops the default event action from happening, whilereturn falsealso stops bubbling (does bothpreventDefaultandstopPropagation)