Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highlight the input field for error with jquery like twitter bootstrap

I have the below sample html code, where i am trying to highlight the input field like input field validation in twitter bootstrap

<html>
<head>
$('#submit_form').submit(function(){
     var vals = $('.validate').val()
     if (!vals) 
        {
          console.log('Error exists');
          $('.validate').attr('style', "border-radius: 5px; border:#FF0000 1px solid;");
          $('.validate').val('enter a value');
        }   
});
</head>
<body>
    <form action="" method="post" id="submit_form">
      <div>
        <input class="validate" type="text" name="Name"/>
      </div>
      <input type="submit" value="Submit">
    </form>
</body>
</html>

So by the above code the value "enter a value" is updating in the field, but the field is not highlighting

Also when i checked whether the style attribute has added to input.. and yes it was added successfully but why the field is not highlighting

like image 727
Shiva Krishna Bavandla Avatar asked Nov 28 '13 13:11

Shiva Krishna Bavandla


1 Answers

try this

$('.validate').css({ "border": '#FF0000 1px solid'});

by replacing

$('.validate').attr('style', "border-radius: 5px; border:#FF0000 1px solid;");
like image 83
prabu Avatar answered Sep 20 '22 18:09

prabu