How to Set a Form Checkbox to Always Default to be Checked

Note: Please ensure that you have access to an experienced JavaScript developer, because Marketo Technical Support is not set up to assist with troubleshooting custom JavaScript

Follow the steps described in this article if you want to force a checkbox to always be checked regardless of the database value - for instance, an email opt-in checkbox. 

Get the field's ID

First, get the HTML ID for the form field you want to edit.  In Design Studio, select a landing page that contains the form and preview the page.

View the HTML source code of that page and find the field you want.  The fastest way is to search for the label that you used when you created the form, such as "Opt-In".

Search for the "id" attribute in the "input" tag for that field.  Below, the id is "Opt-In".

<label>First Name:</label><span class='mktInput'><input class='mktFormCheckbox' name='Opt-In' id='Opt-In' type='checkbox' value='1' tabIndex='1' /><span class='mktFormMsg'></span>

Setting the checkbox

Write Javascript to change the value of that field.  This example uses the jQuery "attr" function to set the value to true (checked).

Change the highlighted yellow bits below with the name of the field.

<script language="Javascript" src="/js/public/jquery-latest.min.js" type="text/javascript"></script>
<script type="text/javascript">
    // use no conflict mode for jQuery
  var $jQ = jQuery.noConflict();

    // when the page is ready, change Opt-In
  $jQ(document).ready(function() {
    $jQ('#Opt-In')
.attr('checked',true);

  });
</script>

When you're done, add the Javascript to your landing page by dragging in a Custom HTML element on the page, then paste in this code.