Validate ID in the database

-3

Very good people ... I need a little help ... I have a form made by which the user must enter a name, ID, sex..by which then it is saved to a database ... I have to do a function in javascript to check if the ID was already entered .. If this ID was already saved when I click on the "save" button I see an error sign and do not let me save ... greetings and thanks for your time ..I am working with mongodb and nodejs

    
asked by Lucas Pupilli 03.09.2018 в 20:30
source

1 answer

2

Look something like this with Jquery

    function Get_Campo(DNI){
        var salida="";
        $.ajax({
            type:"POST",
            url:"<?=$_SERVER["PHP_SELF"]?>",
            data:({
                funcion:"Validar_DNI",
                dni:DNI
            }),
            dataType:"html",
            async:false,
            success:function(msg){
                salida=msg;
                return salida;
            }
        }); 
        return salida;
    }

    var G=Get_Campo($("#DNI").val());
if(G=="1") alert("Existe");

This call <?=$_SERVER["PHP_SELF"]?> refers to the current file in PHP, it can be replaced by the file where is the connection to the BD of your validator

    
answered by 03.09.2018 в 20:35