I have tried the following javascript page loaders for the sake of trying what's not working:
window.location.href = url
window.location = url
window.location.assign(url)
window.location.redirect(url)
Not one of them makes it to the correct page. And everytime I click on the button, it keeps on catching the first if case even though I clicked the second button. Am I doing something wrong with my if-else statements or the way I redirect it?
I also tried doing onclick=, paired with a switch case, window.location.href still doesn't come through.
My HTML:
<form id="action_option" onsubmit="redirect_to_url()" action="">
        <input type="submit" class="btn btn-primary btn-lg btn-space col-sm-3" value="View Object"/>
        <input type="submit" class="btn btn-primary btn-lg btn-space col-sm-3" value= "View Detail"/>
        <input type="submit" class="btn btn-primary btn-lg btn-space col-sm-4" value="View Inventory"/>
</form>
My Javascript:
 function redirect_to_url(){
    var action_option = document.getElementById("action_option");
    alert(action_option);
    var url = document.URL;
    url = url.slice(0, -1);
    if (action_option.elements[0].click) {
         url = url + "{% url 'objects_view' %}";
         alert(url);
         window.location.href(url);
    }
    else if(action_option.elements[1].click) {
        url = url + "{% url 'details_view' %}";
        alert(url);
        window.location.href(url);
    }
    else {
        url = url + "{% url 'inventory' %}";
        alert(url);
        window.location.href(url);
    }
    return false;
}
Edit:
Console Error -
TypeError: window.location.href is not a function
- Removed Error by changing to window.location.href = urlbut still doesn't redirect.
 
     
     
     
     
    