Support

Account

Home Forums Backend Issues (wp-admin) Regarding Select dropdown on change

Solved

Regarding Select dropdown on change

  • Hello,
    I am currently playing with the code for a select button.

    I would like to add some code when the select field is changed, I am unable to do that.

    I am able to run the JS code properly but the code for select on change doesnt seem to run at all. Perhaps ACF is running select2 in some other way, I dont know.
    Any help would be appreciated.

    This is the code I am running, I have checked up the acf field element ID and it is correct.

    Please help me.

    
    
    // JavaScript Document
    (function($) {
    	$(document).ready(function(){
    		
    		$('select#acf-field_5887df9fb89a9').select2()
    		.on("change", function(e) {
    			alert("change val=" + e.val);
    		});
    
    	});
    })(jQuery);
    

    I am running this in the backend.

    Thanks for any help or advice.

  • I managed to make it work through JQuery,
    we need to check if the input field for the element is changed, here is the code if someone needs it:

    
    // JavaScript Document
    (function($) {
    	$(document).ready(function(){
    		alert ('hejsan test ny3');
    		
    			
    		if ( $( "#acf-field_5887df9fb89a9-input" ).length ) {
    			alert('#acf-field_5887df9fb89a9-input exists yeyyy!' );
    		} 
    			
    		$( "#acf-field_5887df9fb89a9-input" ).change(function(e) {
    			alert( "Handler for .change() called." + e.val );
    		});
    	});
    })(jQuery);
    

    regards

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Regarding Select dropdown on change’ is closed to new replies.