first here is the code:
Part 1
$('#monhpf').keyup(function()
{
/* General variable(s) */
var monhpf = $('#monhpf').val();
if(monhpf=="")
{
$('#monhpf').css('border-color',red);
$('.mondayErrors').text(emptyField).show();
}else
if(monhpf.length > 0)
{
/* Verifies the charset of the zip code */
$.post('functions/hoursCharset.php',{hoursPHP:monhpf},function(hoursCharset)
{
if(hoursCharset==true)
{
/* Charset valid*/
$('#monhpf').css('border-color',green);
$('.mondayErrors').hide();
mondayErrors = false;
}else
{
/* Charset not valid */
$('#monhpf').css('border-color',orange);
$('.mondayErrors').text(invalid).show();
mondayErrors = true;
}
});
}
});
Part 2
$('#monmpf').keyup(function()
{
/* General variable(s) */
var monmpf = $('#monmpf').val();
if(monmpf=="")
{
$('#monmpf').css('border-color',red);
$('.mondayErrors').text(emptyField).show();
}else
if(monmpf.length > 0)
{
/* Verifies the charset of the zip code */
$.post('functions/minutesCharset.php',{minutesPHP:monmpf},function(minutesCharset)
{
if(minutesCharset==true)
{
/* Charset valid*/
$('#monmpf').css('border-color',green);
$('.mondayErrors').hide();
mondayErrors = false;
}else
{
/* Charset not valid */
$('#monmpf').css('border-color',orange);
$('.mondayErrors').text(invalid).show();
mondayErrors = true;
}
});
}
});
As you can see part 1 and part 2 are pretty much the same except for the #monhpf and #monmpf variables. My question is, how can I improve this code to be smaller? Like in a single function for example.