0

i have a table with input in all of rows, i need to check if all input are filled with values I tried to use the selector $("[id$='txtBarcode']") to select all input that ends with txtBarcode, but it not seems to work. what is wrong?

$(document).ready(function() {
  $("#cmdConferma").click(function() {
    AllFilled();
  });
});

function AllFilled() {
  $("[id$='txtBarcode']").each(function() {
    $this = $(this);
    // var value = $("[id$='txtBarcode']").value();
    if ($this.value() == '') {
      return confirm('are you sure to exit without fill?');
    }
  });
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="table_style" cellspacing="0" rules="all" border="1" id="dgrRighe" style="width:100%;border-collapse:collapse;">
  <tr>
    <td>
      <input name="dgrRighe$ctl02$txtBarcode" type="text" value="1" id="dgrRighe_ctl02_txtBarcode" />
    </td>
    <td>
      <input name="dgrRighe$ctl03$txtBarcode" type="text" id="dgrRighe_ctl03_txtBarcode" />
    </td>
    <td>
      <input name="dgrRighe$ctl04$txtBarcode" type="text" id="dgrRighe_ctl04_txtBarcode" />
    </td>
  </tr>
</table>
<input type="submit" name="cmdConferma" value="exit" id="cmdConferma" class="button" />
guradio
  • 15,524
  • 4
  • 36
  • 57

1 Answers1

4

That is because .value() is not valid jquery method. You need to use .val() instead:

if ($this.val() == '')

also if your goal is to get the value of element, there is no need to create elements jquery object. You can use pure javascript. I will also suggest using trim() to prevent user from entering empty character:

if (this.value.trim() == '')
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
  • `.value()` is not method in javascript as well. its a property. for using `.value` there is no need to convert dom object to jquery object. using `this.value` will return the value – Milind Anantwar May 24 '17 at 14:05