jQuery(document).ready(function($){ var custom_uploader; var row_id jQuery("input[class^='upload_image_button']").click(function(e) { e.preventDefault(); row_id = jQuery(this).attr('id'); //If the uploader object has already been created, reopen the dialog if (custom_uploader) { custom_uploader.open(); return; } //Extend the wp.media object custom_uploader = wp.media.frames.file_frame = wp.media({ title: 'Choose Quote', button: { text: 'Choose Quote' }, multiple: false }); //When a file is selected, grab the URL and set it as the text field's value custom_uploader.on('select', function() { attachment = custom_uploader.state().get('selection').first().toJSON(); jQuery('#field_' + row_id).val(attachment.id); jQuery('#field2_' + row_id).val(attachment.url); var src = $('#thumb_' + row_id).attr("src") var srcreplace = $('#thumb_' + row_id).attr("src").replace(src, attachment.url) $('#thumb_' + row_id).attr("src", srcreplace) }); //Open the uploader dialog custom_uploader.open(); }); $(window).load(function() { var value1 = $('#dropdown1').val() if (value1!='undefined') { switch (value1) { case "1": $('#firstCell').show(); $('#secondCell').hide(); $('#thirdCell').hide(); $('#forthCell').hide(); break case "2": $('#firstCell').show(); $('#secondCell').show(); $('#thirdCell').hide(); $('#forthCell').hide(); break case "3": $('#firstCell').show(); $('#secondCell').show(); $('#thirdCell').show(); $('#forthCell').hide(); break case "4": $('#firstCell').show(); $('#secondCell').show(); $('#thirdCell').show(); $('#forthCell').show(); break } } }); $('#dropdown1').change(function() { var value2 = $(this).val() switch (value2) { case "1": $('#firstCell').show(); $('#secondCell').hide(); $('#thirdCell').hide(); $('#forthCell').hide(); break case "2": $('#firstCell').show(); $('#secondCell').show(); $('#thirdCell').hide(); $('#forthCell').hide(); break case "3": $('#firstCell').show(); $('#secondCell').show(); $('#thirdCell').show(); $('#forthCell').hide(); break case "4": $('#firstCell').show(); $('#secondCell').show(); $('#thirdCell').show(); $('#forthCell').show(); break } }); });