lundi 25 mars 2019

input type checkbox to be true or false depended on the data

I'm trying to create a checkbox, which is depended on the database to show whether it should be initially checked or unchecked.

Played around the checkedbox and value with true/false, 0/1 and ""/blanks

$.each(customers, (index, customer) => {
$('#accordionAlarm').append(
`<tr>
<td class="card">

<input type="checkbox" name="checkBox[]" id="1${customer.customerId}" checked="${customer.alarmDateInitial === 'Y' ?  'true' : 'false' }"></input>
<input type="checkbox" name="checkBox[]" id="5${customer.customerId}" checked="${customer.alarmDateFifth === 'Y' ?  'true' : 'false' }"></input>
<input type="checkbox" name="checkBox[]" id="7${customer.customerId}" checked="${customer.alarmDateSeventh === 'Y' ?  'true' : 'false' }"></input>

</td>
</tr>`)
});

Expected:

  • When data = Y, checkbox is checked
  • When data != Y, checkbox is not checked



Aucun commentaire:

Enregistrer un commentaire