Change border-color according to value of a jquery variable

0

I have a form and I want to change the color of the border-color to red if the user / email has already been registered in my database.

I tried something like:

<script>

        $(document).ready( function(){
            $('#btn_escrever').click(function(){
                if($(usuario_existe == 1){
                    $('#usuario').css({'border-color': '#A94442'});
                }

</script>

Btn_style is the button where I use to register; the user_exist is a variable that I am using through php to check whether the user already exists or not in bd, if it has a value of 1, it already exists. Something is wrong, can anyone help me?

    
asked by anonymous 07.01.2018 / 21:14

1 answer

0

There's a lot wrong with your code.

Well come on, first use that:

$(document).ready( function(){

can be replaced by this:

$(function () {

Well, it's the simplified and new form of jQuery.

Then you need to change this:

if($(usuario_existe == 1){
   $('#usuario').css({'border-color': '#A94442'});
}

Because there are clearly errors, I did so by simulating your php variable with one of javascript, but you only assign the value:

usuario_existe = $('#usuario').val();

if(usuario_existe == 1){
   $('#usuario').css({'border-color': '#A94442'});
   alert('usuario_existe = 1'+usuario_existe);
}

I made this example in this jsfiddle

    
08.01.2018 / 12:36