Checkbox should be checked if the value is passed by javascript in laravel

Tags: ,



i have check box

<input type="checkbox" id="total_distance" {!! (if(value=="1")) ? 'checked="true"': '' !!}>

in javascript i am passing value to checkbox id="total_distance"

var a = 1;
document.getElementById('total_distance').value = a;

i want if passing value == 1 use this value in it and compare it {!! (**here compare**) ? 'checked="true"': '' !!}

Answer

use this one. this should solve your problem with setting value in javascript as you wrote

<input type="checkbox" id="total_distance" {{this.value == 1 ? 'checked' : ''}}>


Source: stackoverflow