Document.locattion.href does not work in javascript


The idea is that, on a page that contains a form, it is redirected from the current page to the main page when it is filled out. The problem is that it stays on the same page. The javaScript code is as follows:

function crearSesion(){
var user=document.getElementById("usuario").value;
var pass=document.getElementById("clave").value;
  if(user!==""&& pass!==""){
    if(user=='' && pass=='javascript'){
       alert("ingresado correctamente");
        alert("no estas registrado");


The call to the function from HTML5 code is as follows:

     <input onclick="crearSesion();"type="submit" value="iniciar sesion" id="enviar">

From already very grateful.


The button does a submit and I think you don't want it to. Therefore you must change the type and pass it to button

<input onclick="crearSesion();"type="button" value="iniciar sesion" id="enviar">
Scroll to Top