Home Forums Backend Issues (wp-admin) Applying javascript to a field using acf/input/admin_head


Applying javascript to a field using acf/input/admin_head

  • I’ve discovered in the documentation the action for applying javascript code to ACF fields (if I’m interpreting this correctly). The documentation can be found HERE

    My problem is that I’m having trouble getting the javascript to work. My code is targeting an ACF checkbox which when checked, is supposed to unhide a div that’s already on the page and hidden.

    My code is:

    	function my_acf_admin_head()
    	<style type="text/css">
    		#CompletedDonorApplication {display:none;background:#eef;padding:10px;text-align:center;}
    	<script type="text/javascript">
    var elem = document.getElementById('CompletedDonorApplication'),
        checkBox = document.getElementById('acf-field-donor_completed_consent');
    checkBox.checked = false;
    checkBox.onchange = function() { = this.checked ? 'block' : 'none';
    add_action('acf/input/admin_head', 'my_acf_admin_head');

    I created my own separate plugin that I use to house scripts that I use to affect core files rather than editing the core files themselves. So in the code example above it would start and end with opening and closing php tags.

    The problem is that this isn’t working. Clicking on the ACF checkbox does not unhide the div like I had hoped. Is there a specific place I should put the above code? Please help.

  • try this way

    <script type="text/javascript">
    		/** your code **/
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Applying javascript to a field using acf/input/admin_head’ is closed to new replies.