Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

input time checking if empty jquery

Why this code is not working ? Even if I fill the input time is triggering alert(’empty’)

<label for="">New ETA:</label>
   <input type="time" class="neweta">
   <input type="button" onclick="newetasave(this)" value="save"></br>

function newetasave(t){
 var tr = $(t).closest('tr').prev()
 var neweta = $(t).prev('input').val()

 if ($(neweta).val("")) {
   alert('empty')

 }else {
   alert('not empty')
// $(tr).find('.eta').text(neweta)
 }
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Your code is incomplete, i strongly recommend going through the jQuery documentation first.

Your code needs to be something like this:

function newetasave(t){
 var tr = $(t).closest('tr').prev();
 var neweta = $(t).prev('input'); //Now its a jquery object

 if ($(neweta).val().length == 0) {
   alert('empty');

 }else {
   alert('not empty')
// $(tr).find('.eta').text(neweta)
 }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<label for="">New ETA:</label>
   <input type="time" class="neweta">
   <input type="button" onclick="newetasave(this)" value="save"></br>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading