Skip to content

Instantly share code, notes, and snippets.

@longjasonm
Created February 25, 2013 20:56
Show Gist options
  • Save longjasonm/5033215 to your computer and use it in GitHub Desktop.
Save longjasonm/5033215 to your computer and use it in GitHub Desktop.
Show/hide fields dynamically on Marketo forms.
<script type="text/javascript">
var $jQ = jQuery.noConflict();
$jQ(document).ready(function(){
//This code shows a field with ID = "State" when the value of field ID = "Country" is "Australia".
//Add this code to an HTML block on the landing page.
// Put the ID of the dynamic field here
var stateRow = $jQ("#State").parents("li:first");
var stateField = $jQ("#State");
// The ID of the controlling/triggering field
$jQ("#Country").change(function() {
var value = this.value;
// when case value ="[Desired Value]", show the dynamic field and make it required
// if not, hide the dynamic field
switch(value)
{
case "Australia":
stateField.addClass("mktFReq");
stateRow.addClass("mktFormReq").slideDown();
break;
default:
stateRow.removeClass("mktFormReq").slideUp();
stateField.removeClass("mktFReq");
}
}).change();
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment