How to validate multiple textboxes using jquery?
Today we are going to see about Multiple textbox validation using jquery.In my example i change the border color of the textbox to red if it is empty else i change the color to skyblue.For this i'm using class selector.Here we go,
Jquery
$('#btnsave').click(function(){
$('.test').each(function(){
if($(this).val()=' ')
{
$(this).css('border-color','red');
}
else
{
$(this).css('border-color','skyblue');
}
});
});
HTML
<div class='container'>
<input type='text' class='form-control test' />
<input type='text' class='form-control test' />
<input type='text' class='form-control test' />
<input type='text' class='form-control test' />
</div>
<div class='btn btn-primary' id='btnsave'>Click me</div>
Jquery
$('#btnsave').click(function(){
$('.test').each(function(){
if($(this).val()=' ')
{
$(this).css('border-color','red');
}
else
{
$(this).css('border-color','skyblue');
}
});
});
HTML
<div class='container'>
<input type='text' class='form-control test' />
<input type='text' class='form-control test' />
<input type='text' class='form-control test' />
<input type='text' class='form-control test' />
</div>
<div class='btn btn-primary' id='btnsave'>Click me</div>
Comments
Post a Comment