Last active
August 29, 2015 14:07
-
-
Save i5ar/20596d66988eb40be6cc to your computer and use it in GitHub Desktop.
Forms with Conditional Logic
This file contains 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
jQuery(document).ready(function() { | |
// Hide the field initially | |
jQuery(".field_2").hide(); // <div class="field_2"> | |
// Show the text field only when the third option is chosen - this doesn't | |
jQuery('#field_1').change(function() { // <select id="field_1"> | |
if (jQuery("#field_1").val() == "Nope") { // <option value="Nope"> | |
jQuery(".field_2").show(); | |
} else { | |
jQuery(".field_2").hide(); | |
} | |
}); | |
}); |
This file contains 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
<div class="editfield field_1 field_one required-field visibility-public alt field_type_selectbox"> | |
<label for="field_1">Field One</label> | |
<select id="field_1" name="field_1" aria-required="true"> | |
<option value="">----</option> | |
<option value="Yes">Yes</option> | |
<option value="Nope">Nope</option> | |
<option value="Maybe">Maybe</option> | |
</select> | |
</div> | |
<div class="editfield field_2 field_two optional-field visibility-public field_type_textbox" style="display: block;"> | |
<label for="field_2">Field Two</label> | |
<input id="field_2" name="field_2" type="text" value=""> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment