$(document).ready(function(){

  $('#successImage').hide();
  $('#errorImage').hide();
  getInstitutions();
  getRoles();
  $('#registrar').click(function(){
    insertUserInDb();
  });
});

function validate(){

  if($('#nombre').val().length == 0){
    return false;
  }

  if($('#password1').val().length == 0){
    return false;
  }

  if($('#password1').val() != $('#password2').val()){
    return false;
  }

  return true;
}


function insertUserInDb(){
  if(validate()){

    var userName = $('#nombre').val();
    var passwordUser = $('#password1').val();
    var institutionId = $('#institutionCombo').val();
    var rolId = $('#rolesCombo').val();

    alert("instId" + institutionId + " rolId:" + rolId + " pASS: " + passwordUser);
    $.post("../Controladores/insertions.php", {
      action: "insertUser",
      user: userName,
      password: passwordUser,
      instId: institutionId,
      roleId: rolId
    }, function(data){
      if(data == "1"){
        success();
      }else{
        failed();
      }
    });
  }else{
    alert("Fields are NOT validate");
  }

}

function success(){
  $('#successImage').show();
  $('#nombre').val() = "";
  $('#password1').val() = "";
  $('#password2').val() = "";
}

function failed(){
  $('#errorImage').show();
  $('#nombre').val() = "";
  $('#password1').val() = "";
  $('#password2').val() = "";
}

function getInstitutions(){

  $.post("../Controladores/getInfo.php", {
        action: "getInstitutions",
  },
  function(data){

    $("#institutionComboPos").append("<select id='institutionCombo'>" + data + "</select>");
    $('#institutionCombo').material_select();
  });
}


function getRoles(){
  $.post("../Controladores/getInfo.php", {
      action: "getRoles",
  },
  function(data){
    $("#rolesComboPos").append("<select id='rolesCombo'>" + data + "</select>");
    $('#rolesCombo').material_select();
  });
}

@@ -1122,32 +1122,59 @@
 Image').show();%0A
+  $('#errorImage').hide();%0A
   $('#nombre').v
@@ -1168,38 +1168,35 @@
 ('#nombre').val(
-) = 
 %22%22
+)
 ;%0A  $('#password
@@ -1195,38 +1195,35 @@
 password1').val(
-) = 
 %22%22
+)
 ;%0A  $('#password
@@ -1222,38 +1222,35 @@
 password2').val(
-) = 
 %22%22
+)
 ;%0A%7D%0A%0Afunction fa
@@ -1280,24 +1280,53 @@
 e').show();%0A
+  $('#successImage').hide();%0A
   $('#nombre

Change input values after success