Search code examples
javascriptjqueryw2ui

Set a checbox checked by default on an autogenerated form


I have a form with few fields, and it autogenerating the HTML, and i'd like to keep it that way.

$('#tabTabData').w2form({
  header: 'Data',
  name: 'formEdit',
  url: '******.asp',
  fields: [
    { name: 'Active',   type: 'checkbox', required: false, html: { caption: 'Active',  attr: 'size="40"' } },
    { name: 'Visible',  type: 'checkbox', required: false, html: { caption: 'Visible',  attr: 'size="40"' } }
  ],

I want that those checkbox appear as checked by default. I tried adding checked to the attr and did not work. I submit how the line is by adding that:

{ name: 'Visible', type: 'checkbox', required: false, html: { caption: 'Visible', attr: 'size="40" checked' } }

Any help It would be very much appreciated, I could also do it by using Javascrip/jQuery, but those are my options.

Thanks again ;)


Solution

  • via jQuery, the best option is $('#my_checkbox').prop('checked', true); rather than using .attr