Created
February 25, 2013 20:56
-
-
Save longjasonm/5033215 to your computer and use it in GitHub Desktop.
Show/hide fields dynamically on Marketo forms.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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