Created
January 25, 2012 17:42
-
-
Save tnorthcutt/1677531 to your computer and use it in GitHub Desktop.
Autofill a set of fields (in a gravity form, in this case) based on a checkbox being checked.
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($) { | |
$('input#choice_13_1').click(function() { | |
if($(this).is(':checked')) { | |
$('#input_2_12_1').val($('#input_2_2_1').val()); | |
$('#input_2_12_2').val($('#input_2_2_2').val()); | |
$('#input_2_12_3').val($('#input_2_2_3').val()); | |
$('#input_2_12_4').val($('#input_2_2_4').val()); | |
$('#input_2_12_5').val($('#input_2_2_5').val()); | |
}; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For anyone still wondering, this needs to go in a javascript file that gets enqueued in functions.php, as here, and should be placed in document.ready(). Another way to do it more generally is the following:
Then all you need to do is create a checkbox with the CSS class "fill-check," give the fields you want to fill from the class "fill-from," and give the fields you want to fill into the class "to-fill" (classes can be added under the "appearance" tab on forms). As long as the labels for the fields are the same, it should work.