var disabled = '';
if(value.action.length === 0)
{
disabled = 'disabled="disabled"';
}
row += '<td><input type="checkbox" name="create" value="1" class="checkbox" data-action="'+ value.action + '" data-controller = "'+ value.controller +'" data-role="'+ role +'" document.write(disabled)></td>';
I want to print disabled="disabled" based on the truthfulness of my condition. In PHP this can be easily done by the method I used above but I failed to to it in JavaScript. The document.write() is getting printed as it is.
How can I do this in JavaScript?
document.writehere, simply concat the strings as you did before:… + '" ' + disabled + '></td>';or even with less code:… + '"' + ( value.action.length === 0 ? ' disabled' : '' ) + '></td>';