jQuery( document ).ready(function( $ ) { var ajax_uri = 'https://grad.wisc.edu/wp-content/plugins/iadmiss/get_iadmiss.php'; $( '.iadmiss-country-select-field' ).each( function() { processCountry( this ); }); $( '.iadmiss-country-select-field' ).change( function() { processCountry( this ); }); $( '.iadmiss-school-select-field' ).each( function() { processSchool( this ); }); $( '.iadmiss-school-select-field' ).change( function() { processSchool( this ); }); $( '.iadmiss-widget-main select' ).select2(); function processCountry( field ) { var schools = $( field ).parents( '.iadmiss-selectors' ).find( '.iadmiss-school-select-field' ); $( schools ).empty(); $( schools ).append( '' ); var country_req = ajax_uri + '?' + $.param({ country: $( field ).val() }); $.getJSON( country_req, function( data ) { $.each( data, function( i, v ) { $( schools ).append( '' ); }); $( schools ).select2(); }); } function processSchool( field ) { var display = $( field ).parents( '.iadmiss-widget-main' ).find( '.iadmiss-data-field' ); if( $( field ).val() != 0 ) { var school_req = ajax_uri + '?' + $.param({ req: "school", id: $( field ).val() }); $( display ).show(); $.getJSON( school_req, function( data ) { $.each( data, function( i, v ) { if( i == 'text' ) { v = v.replace( /-Madison/g, '–Madison' ); v = v.replace( //g, '
' ); v = v.replace( /
/g, '
' ); } $( display ).find( '.' + i + ' > .data' ).html( v ); }); }); } else { $( display ).hide(); } } });