location.href with a jquery handler

I have the next code.

$(function(){
    var cambio=false;
        var codigoAlumno="";
        $("select").change(function(){
             codigoAlumno=$(this).val();
             cambio=true;
        });

        $("#insertar").on('click',function(){
            alert("has hecho click");
            alert(cambio);
            if(cambio===true){
                window.location.href='../../Servlet?submit=Insertar Alumnos&codigoA='+codigoAlumno;
            }
        });
    });

I want that when it's a change in my select catch the value and when i submit with the button pass it to my servlet.

If i put location.href outside of the handler it works but when it's in no.

When it's inside even I tried to go to other page and it doesn't work either

Upvotes: 1

Views: 95

Answers (1)

Naresh
Naresh

Reputation: 2781

Try with return false.

  if(cambio===true){
       window.location.href='../../Servlet?submit=Insertar Alumnos&codigoA='+codigoAlumno;
       return false;  
    }

Upvotes: 1

Related Questions