javascripthtmlwindow.location

redirect event with javascript


I'm doing a project and I don't understand the front end well. I have this html page:

<form class="form-group" action="/create" method="post" enctype="multipart/form-data">

            <div class="title">
                <h1>Cadastre seu produto</h1>
            </div>

            <div class="single-input">
                <input class="form-control" placeholder="nome do produto" type="text" id="nome_produto" name="nome_produto">
            </div>

            <div class="single-input">
                <input class="form-control" placeholder="quantidade em estoque" type="number" id="quantidade" name="quantidade">
            </div>

            <div class="single-input">
                <input class="form-control" placeholder="preco do produto" type="number" id="preco_produto" name="preco_produto">
            </div>
            <button onclick="loadPage()" id="button" type="submit" class="btn btn btn-danger">ENVIAR</button>
        </form>       

I want that when I click on the SUBMIT button, I am redirected to another page, I want to do this using Javascript.

I tried to do this:

<script type="text/javascript">
function loadPage(){
    window.location("http://localhost:8080/list")
}

but it's not working, every time I click on the button I'm redirected to a blank page Any solution ?


Solution

  • Window.location is a property not a function. So it should be

    window.location = "http://localhost:8080/list";
    

    More details here: https://developer.mozilla.org/en-US/docs/Web/API/Window/location