Wellington Gallo Posted May 27, 2015 Report Share Posted May 27, 2015 Boa tarde, gostaria de saber como que faço parar fazer com que o valor da hora informado pelo usuario seja menor que a hora atual. Eu fiz assim e não funcionou : var date = new Date; if ($('#hr_agendamento').val() < date.getHours()) { alert('teste'); } Quote Link to comment Share on other sites More sharing options...
0 wootzor Posted May 27, 2015 Report Share Posted May 27, 2015 É isto que pretendes? $(document).ready(function() { var date = new Date; $("button").click(function() { if ($('#hr_agendamento').val() < date.getHours()) { alert('teste'); } }); }); Se em vez de utilizares um botão quiseres que a verificação seja feita quando passas para a próxima caixa de texto utiliza o evento .change da caixa de texto. $(document).ready(function() { var date = new Date; $('#hr_agendamento').change(function() { if ($(this).val() < date.getHours()) { alert('teste'); } }); }); Quote Link to comment Share on other sites More sharing options...
0 Wellington Gallo Posted May 28, 2015 Author Report Share Posted May 28, 2015 Mexi no sistema e não podia deixar o usuario cadastrar um agendamento para a hora menor que a atual, fiz desse jeito. $('#hr_agendamento').blur(function() { var date = new Date(); var diaAtual = date.getDate(); var mesAtual = date.getMonth(); var anoAtual = date.getFullYear(); if(diaAtual < 10){ diaAtual = '0'+diaAtual; } mesAtual = mesAtual +1; if(mesAtual < 10){ mesAtual = '0'+mesAtual; } var diaFormatoAtual = diaAtual+"/"+mesAtual+"/"+anoAtual; console.log(diaFormatoAtual); if ($('#dt_agendamento').val() == diaFormatoAtual) { var horaAtual = date.getHours()+":"+date.getMinutes(); if ($('#hr_agendamento').val() < horaAtual) { alerta('Hora não permitida', 'Ação não permitida'); $(this).val(''); } } }); Mas segui teu exemplo e também está Ok. Obrigado :D Quote Link to comment Share on other sites More sharing options...
Question
Wellington Gallo
Boa tarde, gostaria de saber como que faço parar fazer com que o valor da hora informado pelo usuario seja menor que a hora atual.
Eu fiz assim e não funcionou :
Link to comment
Share on other sites
2 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.