Ethris Ethris - 3 months ago 14
Javascript Question

Javascript window.location does not work

I have problem with this code that I can not understand.

Window.location
worked perfectly for me before but this time its not and I have no idea. When I access this direction manually - it works, but redirect does not work - just refreshes page. I have no clue what to do !

I've tried to redirect it to google or whatever but it still just refreshes.

$("#remove-form").on("submit", function(event) {
usunRow();
});

function remove() {
var id=document.getElementById("id").innerHTML;
if (id != "ID"){
$('#remove-modal').modal('show');
} else $('#error-modal').modal('show');
}

function usunRow(){
var id=document.getElementById("id").innerHTML;
if (id != "ID"){
window.location.href = "usun.php?id="+id;
alert("usun.php?id="+id);
} else $('#error-modal').modal('show');
}


here's all functions I am using for this

Answer

Change window.location to window.location.href this will changes the window location to a new location.

  1. Make sure your usunRow() function call perfectly and there is no issue in your browser console.
  2. Also make sure your if statement executes, may be your if statement is not executing that will be the reason that your page just refreshes not changing its location.

UPDATED

Add return false, because submitting a form will refresh your page return false will keep the page static and your window.location.href will redirect your page.

$("#remove-form").on("submit", function(event) {
            usunRow();
            return false;
});

Hope this solve your issue.

Comments