// Whenever someone changes the value of an element with the id of 'category_id' trigger this event...
$(document).on('change', '#category_id', function(event) {
// Prevent the default action taking place (the changing of the value)
event.preventDefault();
// Instead, get the value of the element that is triggering the event (the category_id element)
id = $(this).val();
// Find the element with the id 'sub_category_id' and replace its contents with the value stored
// in the sub_categories_array at the given ID (the value entered in the category_id element)
$('#sub_category_id').html(sub_categories_array["'"+id+"'"]);
});
// When the element 'sub_categories_' changes, redirect the browser to the specified path
$(document).on('change','#sub_categories_', function(event) {
// The path is based on the value of the ID parameter passed to the page and the value from the 'sub_categories_' element.
window.location.href = site_url+'/videos/category/<?php echo($_GET['id']) ?>/'+$('#sub_categories_').val();
});
In the future, you can throw in some of your own console.log and use dev tools to figure out what a piece of code does.