Skip to content

Instantly share code, notes, and snippets.

@n05la3
Created November 23, 2017 18:06
Show Gist options
  • Save n05la3/183db88aa0a0f3595d30115d59e9968c to your computer and use it in GitHub Desktop.
Save n05la3/183db88aa0a0f3595d30115d59e9968c to your computer and use it in GitHub Desktop.
Notify when required form field is skipped
<script>
$('document').ready(
function(){
$('input').on('click focus',
function(){
//sample form id in order of appearance
var fillable = ['fn', 'ln', 'age', 'email', 'pass', 'pass_ok'];
$('input').css('border', '');
for(var i = 0; i<=fillable.indexOf(this.id); ++i){
z = $('#'+fillable[i]);
//reset border to default
if(this.id === fillable[i]){
$(z).css('border', '');
//y.style.border = '';
break;
}
if( $(z).val() === ''){
//sample notification
$(z).css('border','2px solid red');
//y.placeholder = y.placeholder + ' is required';
break;
}
}
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment